Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How to create a quotation containing the given token in a syntax word in Factor programming language
I am trying to define a syntax word as follows:
USING: kernel syntax parser fry prettyprint ;
IN: syn-try
SYNTAX: syn scan-word '[ _ ] . ;
Given a word, I want to create a quotation containing the word.
In the factor listener, if i do syn word
I get [ \ word ]
. How do I remove the \
?
Language version is Factor 0.98 for Linux.
2 answers
Things must have changed, on .99 I get
syn this
[ "this" ]
The following users marked this post as Works for me:
User | Comment | Date |
---|---|---|
Razetime | (no comment) | Aug 17, 2022 at 11:49 |
When you curry or fry a word into a quotation, the word is first placed into a wrapper
object. This way, when the quotation is called, it places the word literal back on the stack instead of calling the word:
1 2 \ + [ ] 3curry ! [ 1 2 \ + ]
call ! 1 2 + (not 3)
My guess is this behavior was predicted to be useful, although in my opinion it is not.
You could solve this problem by converting wrappers to the objects they wrap...
USING: accessors fry parser prettyprint sequences ;
SYNTAX: syn scan-word '[ _ ] [ wrapped>> ] map . ;
However, it would be easiest to use 1quotation
, which does not wrap anything.
USING: parser prettyprint quotations ;
SYNTAX: syn scan-word 1quotation . ;
0 comment threads