Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Post History

66%
+2 −0
Q&A How to create a quotation containing the given token in a syntax word in Factor programming language

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 callin...

posted 1y ago by chunes‭  ·  edited 1y ago by chunes‭

Answer
#5: Post edited by user avatar chunes‭ · 2022-08-16T14:21:19Z (over 1 year ago)
  • 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 . ;
  • ```
  • 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 . ;
  • ```
#4: Post edited by user avatar chunes‭ · 2022-08-16T14:19:48Z (over 1 year ago)
  • 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 . ;
  • ```
  • Another approach is to use regular sequence words to build the quotation. This is fine to do before run time, as the stack effect checker can still infer a stack effect.
  • ```
  • USING: parser prettyprint sequences ;
  • SYNTAX: syn [ ] scan-word suffix . ;
  • ```
  • 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 . ;
  • ```
#3: Post edited by user avatar chunes‭ · 2022-08-16T14:17:40Z (over 1 year ago)
  • 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.
  • One way to solve this issue is to convert wrappers to the objects they wrap:
  • ```
  • USING: accessors fry parser prettyprint sequences ;
  • SYNTAX: syn scan-word '[ _ ] [ wrapped>> ] map . ;
  • ```
  • It would be easiest to use `1quotation`, which does not wrap anything:
  • ```
  • USING: parser prettyprint quotations ;
  • SYNTAX: syn scan-word 1quotation . ;
  • ```
  • Another approach is to use regular sequence words to build the quotation. This is fine to do before run time, as the stack effect checker can still infer a stack effect.
  • ```
  • USING: parser prettyprint sequences ;
  • SYNTAX: syn [ ] scan-word suffix . ;
  • ```
  • 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 . ;
  • ```
  • Another approach is to use regular sequence words to build the quotation. This is fine to do before run time, as the stack effect checker can still infer a stack effect.
  • ```
  • USING: parser prettyprint sequences ;
  • SYNTAX: syn [ ] scan-word suffix . ;
  • ```
#2: Post edited by user avatar chunes‭ · 2022-08-16T14:07:49Z (over 1 year ago)
  • Use `1quotation`:
  • ```
  • USING: parser prettyprint quotations ;
  • IN: syn-try
  • SYNTAX: syn scan-word 1quotation . ;
  • ```
  • Another way:
  • ```
  • USING: parser prettyprint sequences ;
  • IN: syn-try
  • SYNTAX: syn [ ] scan-word suffix . ;
  • ```
  • If you need to build a more complex quotation, you can do something akin to this:
  • ```
  • USING: parser prettyprint quotations ;
  • IN: syn-try
  • << SYNTAX: syn scan-word 1quotation '[ 1 2 @ ] . ; >>
  • syn +
  • ```
  • Result:
  • `[ 1 2 + ]`
  • 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.
  • One way to solve this issue is to convert wrappers to the objects they wrap:
  • ```
  • USING: accessors fry parser prettyprint sequences ;
  • SYNTAX: syn scan-word '[ _ ] [ wrapped>> ] map . ;
  • ```
  • It would be easiest to use `1quotation`, which does not wrap anything:
  • ```
  • USING: parser prettyprint quotations ;
  • SYNTAX: syn scan-word 1quotation . ;
  • ```
  • Another approach is to use regular sequence words to build the quotation. This is fine to do before run time, as the stack effect checker can still infer a stack effect.
  • ```
  • USING: parser prettyprint sequences ;
  • SYNTAX: syn [ ] scan-word suffix . ;
  • ```
#1: Initial revision by user avatar chunes‭ · 2022-08-16T13:11:40Z (over 1 year ago)
Use `1quotation`:

```
USING: parser prettyprint quotations ;
IN: syn-try
  
SYNTAX: syn scan-word 1quotation . ;
```

Another way:

```
USING: parser prettyprint sequences ;
IN: syn-try
  
SYNTAX: syn [ ] scan-word suffix . ;
```

If you need to build a more complex quotation, you can do something akin to this:

```
USING: parser prettyprint quotations ;
IN: syn-try
  
<< SYNTAX: syn scan-word 1quotation '[ 1 2 @ ] . ; >>

syn +
```
Result:
`[ 1 2 + ]`