Question

I am having a problem with:

>> parse [a / b] ['a '/ 'b]
** Syntax Error: Invalid word-lit -- '
** Near: (line 1) parse [a / b] ['a '/ 'b]
>>
Was it helpful?

Solution

REBOL's interpreter has some limitations on what you can happily write on the command line. You can't get a lit-word by writing '/ -- it throws an error because REBOL knows that / is the op! for division:

'/
** Syntax Error: Invalid word-lit -- '

But you can create '/ as a lit-word, starting with a string:

to-lit-word "/"
== '/

A solution to your code issue:

parse [a / b] compose ['a (to-lit-word "/") 'b]
=== true
  • compose [...] -- means we'll selectively evaluate part of the block before the parse
  • (...) -- is the part that is selectively evaluated, thus creating the desired '/ lit-word
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top