World: r3wp
[Rebol School] Rebol School
older newer | first last |
kib2 8-Feb-2009 [1578] | Geomol: I just followed the book I bought, it tells me that func uses globals, and globals may not be the best no ? |
Geomol 8-Feb-2009 [1579x4] | hm, you can make locals with FUNC. |
It doesn't work, because RETOUR isn't defined. You just declare it (as a block). You need to actually make the block. | |
quartile: func [ liste [block!] /local malong retour ][ retour: clear [] malong: length? liste either (modulo malong 2) [ insert retour (length? liste) ] [ print "longueur impaire" ] return retour ] | |
That may not be, what you want. I haven't figured out yet, what you want the function to do. :-) | |
kib2 8-Feb-2009 [1583x2] | Geomol: thanks! so when you declare an object, it's not build ? |
don't mind about that function purpose : it does nothing interesting at the moment | |
Geomol 8-Feb-2009 [1585x2] | :-) Careful. We have to get the terms right, because they mean something, declare, object, etc. |
Examples of words, that get declared (defined or known from now on) and also get build: a: none b: 42 c: make block! 16 If you specify words to be local to a function, they don't get declared (build). It just mean, that when you refer to those words, they will be local to the function. | |
kib2 8-Feb-2009 [1587] | Geomol: right, i'll try to take care of my vocabulary :) |
Geomol 8-Feb-2009 [1588] | so my-func: func [ var1 var2 /local var3 var4 ][ ..... ] In this, var1 and var2 are two arguments to the function. var3 and var4 are treated local to the function, but they're not created yet. |
kib2 8-Feb-2009 [1589] | Thanks Geomol, that's clearer now. I had to go for lunch, I'll be back in a few mins. (I've got a lot of questions, I find my book not clear at all). |
Geomol 8-Feb-2009 [1590x3] | An example: >> fibonacci: func [i /local n old-n older-n] [n: 1 old-n: 0 loop i [older-n: old-n old-n: n n: old-n + older-n print n]] >> fibonacci 5 1 2 3 5 8 |
I said "careful" up there, becuse you also have objects in REBOL. | |
Another version, you might find useful (at least to see how to make the same thing in different ways, and with different number of variables): fibonacci: func [ i /local a b ][ set [a b] [1 1] loop i [ print a set [a b] reduce [b a + b] ] ] | |
kib2 8-Feb-2009 [1593x2] | nice! |
I said my book wasn't clear because in presenting blocks, it uses the words "arrays", then "lists" and "series" inside : it's quiet confusing. | |
Geomol 8-Feb-2009 [1595x2] | I guess, words like "arrays" and "lists" are common in other languages. In REBOL, you'll see the word "series" a lot. |
A block is a series of elements (inside [ and ]). | |
kib2 8-Feb-2009 [1597] | Geomol: ok, but is there any difference between all these terms ? |
Geomol 8-Feb-2009 [1598] | Try in the REBOL console: >> ? datatype! |
Henrik 8-Feb-2009 [1599] | you can ask whether a datatype is a series with 'series?. |
kib2 8-Feb-2009 [1600] | So what's the difference between a block and a serie ? A serie is a block for me no ? (the inverse may not be right) |
Henrik 8-Feb-2009 [1601] | not all series are alike. We tend to differ between strings and blocks and blocks come in a few different types, optimized for specific use, but they may hold the same content. |
Geomol 8-Feb-2009 [1602] | A computer language theorist might tell you differences between arrays, lists and series. I suggest, you take the practical view and look at what datatypes, you find in REBOL. |
Henrik 8-Feb-2009 [1603] | kib2, let REBOL decide what is what, by asking the datatype: >> series? [a b c] == true >> series? "abc" == true You can do that, because REBOL has so many different datatypes, allowing you to be precise in your expression. |
Geomol 8-Feb-2009 [1604] | >> series? "abc" == true >> series? [] == true >> series? make list! 10 == true So there are many kinds of series. |
kib2 8-Feb-2009 [1605] | Geomol: Rebol is the langage where I've found the more datatypes ! |
Geomol 8-Feb-2009 [1606x2] | hehe :-) |
kib, me too. | |
Henrik 8-Feb-2009 [1608] | if we didn't have this many datatypes (R3 has even more), parsing and dialects would be less fun. |
Geomol 8-Feb-2009 [1609] | kib, you'll see, the number of datatypes is one of the really really huge forces of rebol. |
kib2 8-Feb-2009 [1610x2] | email!, url!, money! etc. That's good when you parse something |
Henrik: R3 adds other datatypes ? like ? | |
Henrik 8-Feb-2009 [1612] | yeah, email! is actually an exception. it doesn't work very well. you will find that a few types can't be serialized properly, which means an email! can't be recognized. but it works for the majority of types. |
Geomol 8-Feb-2009 [1613] | Or when you use functions: read %disk-file read http://www.rebol.com (or reading some other port) |
Henrik 8-Feb-2009 [1614x2] | kib2, percent!, task!, vector!, gob!, handle!, closure!. There are more. |
plus in R3 you can define your own and group types in new ways. | |
kib2 8-Feb-2009 [1616] | really impressive |
Henrik 8-Feb-2009 [1617x2] | using typesets, you can say something like: >> image-type: make typeset! [binary! image! url!] == make typeset! [binary! image! url!] (doesn't make that much sense, but you get the idea.) |
(that's also R3 only) | |
Geomol 8-Feb-2009 [1619] | Henrik, is there an example of a user defined datatype in R3 somewhere? |
Janko 8-Feb-2009 [1620] | wow, you can make your own and combine.. that seems very good! |
Henrik 8-Feb-2009 [1621] | kib2, using MOLD/ALL, you can study serialization, on how to build serialized blocks of data. |
kib2 8-Feb-2009 [1622] | cool and powerful, but we've to wait until R3 gets more stable. |
Henrik 8-Feb-2009 [1623x2] | Geomol, try: ? typeset! Some interesting ones turn up. |
actually only one at this point (scalar!), but I think there will be more, if it makes sense to have them. | |
kib2 8-Feb-2009 [1625] | Henrik: :) |
Geomol 8-Feb-2009 [1626] | kib, you had other questions from reading the book? |
Janko 8-Feb-2009 [1627] | Will R3 also have something like multiple dispatch then? |
older newer | first last |