Lit-words
[1/4] from: lmecir:vol:cz at: 16-Nov-2009 22:57
Hi all,
this theme pops up on this list from time to time. For some words the
usual (apostrophe-prefixed) syntax (e.g. 'a) does not work.
The most frequently seen idiom looks like:
to-lit-word "/"
to-lit-word "<"
to-lit-word ">"
to-lit-word "<="
to-lit-word ">="
to-lit-word "<>"
etc.
Disadvantages:
*the obvious disadvantage of the above approach is, that it converts
string to word, which is generally not recommended when the word is
known in advance. (I have seen some quirks to occur just because a
string is used)
My suggestion:
define a new AS-LIT-WORD function:
as-lit-word: func ['word [any-word!]] [to lit-word! word]
the above examples then become:
as-lit-word /
as-lit-word <
as-lit-word >
as-lit-word <as-lit-word >as-lit-word <>
Advantages:
*the new idioms are more readable
*the code is faster
*we get rid of the above mentioned quirks
-L
[2/4] from: nick:guitarz at: 17-Nov-2009 1:19
Can anything be done to make the following definition of 'greater work
properly?
as-lit-word: func ['word [any-word!]] [to lit-word! word]
greater: as-lit-word >
either (1 greater 100) [print "yes"][print "no"]
Quoting Ladislav Mecir <lmecir-vol.cz>:
[3/4] from: santilli:gabriele:gmai:l at: 17-Nov-2009 12:11
On Tue, Nov 17, 2009 at 10:19 AM, Nick Antonaccio <nick-guitarz.org> wrote:
> Can anything be done to make the following definition of 'greater work
> properly?
Not on R2. (Besides, you'd want to assign it to the actual op! value,
not to the lit-word! value.)
Regards,
Gabriele.
[4/4] from: lmecir:vol:cz at: 17-Nov-2009 14:50
Nick Antonaccio napsal(a):
> Can anything be done to make the following definition of 'greater work
> properly?
>
> as-lit-word: func ['word [any-word!]] [to lit-word! word]
> greater: as-lit-word >
>
> either (1 greater 100) [print "yes"][print "no"]
>
As Gabriele pointed out, R2 does not support other words, than the
official operators
for infix. But, if you don't mind to use prefix,
then you can do e.g.:
maggiore?: :greater?
maggiore? 1 2 ; == false
maggiore? 2 1 ; == true
-L