Hi,

While this would not be a big change, the Factor parser is not  
extensible in this manner.

I'm not a big fan of method_missing in Ruby, because I think it leads  
to code which is hard to compile efficiently, and hard to understand.  
For example, the Rails framework uses method_missing to implement  
sorting; calling a method named sort_by_date invokes method_missing,  
which parses the string "sort_by_date" to extract the substring  
"date", then sorts the table by that column. The trouble with this  
approach is that it buys you nothing over sort_by("date"); it's just  
obfuscation. Also see this blog entry: http://blog.labnotes.org/ 
2007/02/06/method_missing-best-saved-for-last/

Your specific example can be done with parsing words, but even better  
just an ordinary word taking an object as input:

"ab--ba" shuffle

Then you can use define-transform to turn this into efficient code at  
compile time.

The reason we don't encourage parsing words for this type of thing is  
that parsing words which expand at parse time are lost when you later  
use 'see' to look at the word in the image. At some point, Factor  
will have a structure editor which edits word definitions directly  
and only uses source code for import/export.

Parsing words should be used when they can survive the parser- 
unparser 'round trip'; for example, object literal syntax, and  
defining words.

MEMO: in libs/memoize implementing memoization; right now if you  
'see' a word defined by MEMO: it doesn't redisplay in the original  
form, but it would be easy to extend it to do this; I will at some  
point.

Have fun,

Slava

On 7-Apr-07, at 7:50 AM, Csaba Henk wrote:

> Hi,
>
> I wonder if it is possible to have dynamic word resolution akin the
> "method_missing" like methods in OO languages (invoked as a  
> fallback if
> a method is not defined).
>
> Eg: say I want all words which look as follows:
>   - a sequence of alphabetic characters, with no repetition
>   - followed by dash-dash ("--")
>   - followed by some sequence of the characters which occurred before
>     the dash-dash
>
> to act as shuffle words with stack effect corresponding to the name of
> the word. That is,
>
>   xyzpq--ppqqqx
>
> would be then resolved as a shuffle word with stack effect
> (xyzpq -- ppqqqx).
>
> Is this possible to implement? (Sure it is possible within a special
> parsing scope, delimited by some parsing words. My question regards
> to having such a semantics in the language thoroughout.)
>
> Csaba
>
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to