Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Why is the lit-word! datatype! not working

 [1/4] from: gerardcote:sympatico:ca at: 21-Oct-2005 22:10


Hi List, As I tried to eliminate the need to use the (:) before function names into Higher Order Functions I got this more user friendly version to work for me :
>> my-map: func [f blk /local result] [
[ result: make block! length? blk [ foreach item blk [ [ append/only result do reduce [:f :item] [ ] [ result [ ]
>> my-map 'first ["ab" "cd" "ef"]
== [#"a" #"c" #"e"]
>>
In fact I never got the final objective of eliminate either the : or ' before function names - probably because when called the my-map function calls itself the second item which is another function name. So I realized I could note go farther into this simplification but I like better to use a ' than a : as it seems more natural to me to work with a literal to start with. Being so I tried to add more validation for parameters f and blk as in f [lit-word!] and blk [block!]. To my great surprise I received the following error msg. Can someone help me to better understand how REBOL can send me this error ? Why is 'first not considered as a real lit-word! datatype! ?
>> my-map: func [f [lit-word!] blk [block!] /local result] [
[ result: make block! length? blk [ foreach item blk [ [ append/only result do reduce [:f :item] [ ] [ result [ ]
>> my-map 'first ["ab" "cd" "ef"]
** Script Error: my-map expected f argument of type: lit-word ** Where: halt-view ** Near: my-map 'first ["ab" "cd" "ef"]
>>
Thanks! Regards, Gerard

 [2/4] from: antonr::lexicon::net at: 22-Oct-2005 12:37


Hi Gerard, Look at this: a: 1 ;== 1 a ; you type a word ;== 1 ; it is evaluated and result returned 'a ; you type a lit-word ;== a ; it is evaluated and result returned (a word) to-lit-word 'a ; you type a lit-word, it is evaluated to a word ;== 'a ; but then you converted it back to a lit-word So, in your MY-MAP function below, the 'first lit-word is converted to a word *before* it is passed to the function. The solution is to have MY-MAP accept f as a word!, eg: my-map: func [f [word!] ... Anton.

 [3/4] from: lmecir::mbox::vol::cz at: 22-Oct-2005 7:38


Hi Gerard, I am not sure what you consider user friendly, but you have got the following options for function header: 1) f as a "fetched" argument my-map: func [:f blk] [...] 2) f as an "unevaluated" argument my-map: func ['f blk] [...] 3) f as a "normally evaluated" argument (I prefer this as the most standard using the other variants only in rare cases) my-map: func [f blk] [...]
>Hi List, >As I tried to eliminate the need to use the (:) before function names into Higher Order Functions I got this more user friendly
<<quoted lines omitted: 5>>
>[ foreach item blk [ >[ append/only result do reduce [:f :item]
The expression: do reduce [:f :item] can be replaced by f :item in most situations. The other question has been answered by Anton. -Ladislav

 [4/4] from: gerardcote::sympatico::ca at: 22-Oct-2005 21:13


Thanks Anton and Ladislav, I really think I had some serious misconceptions about all these alternatives representations and why or when to use them. Now is the time for me to clear them before proceeding further. In all cases your explanations will help me to find the best solution for my needs. Regards, Gerard

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted