0

I am having a problem with:

>> parse [a / b] ['a '/ 'b]
** Syntax Error: Invalid word-lit -- '
** Near: (line 1) parse [a / b] ['a '/ 'b]
>>
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Rebol Tutorial
  • 2,738
  • 2
  • 25
  • 36

1 Answers1

1

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
Sunanda
  • 1,555
  • 7
  • 9
  • Great just need a refinement now see below :) – Rebol Tutorial Sep 21 '09 at 22:13
  • See rather http://stackoverflow.com/questions/1458139/rebol-parse-rule-with-compose-deep-and-append-function because it's another question – Rebol Tutorial Sep 22 '09 at 04:45
  • Nitpickin' here: but I think it's the special status of / for PATH! which probably breaks the parsing (as opposed to being the division operator). Note that you can literal quote other ops just fine e.g. '* or '+ ... – HostileFork says dont trust SE Apr 29 '11 at 10:33
  • Of course you can set up a specific rule: `dvdr: reduce [to-lit-word "/"]` and then use this in your main parse rule: `['a dvdr 'b]` – rgchris Jun 19 '11 at 22:55