ForthHub / discussion

Discussion repository for Forth enthusiasts.
118 stars 4 forks source link

Exception handling via a condition system : possible? #111

Open ghost opened 2 years ago

ghost commented 2 years ago

Is it possible for a Forth to have a Common Lisp like "condition handling" system? More about "condition handling"; https://en.wikibooks.org/wiki/Common_Lisp/Advanced_topics/Condition_System

MitchBradley commented 2 years ago

The Forth systems that I used to provide in 80s and 90s - with names like ForthMacs, Sun Forth, and Open Firmware - all had exception handling of that ilk. I'm sure there are other Forth systems with such capabilities.

ruv commented 2 years ago

Is it possible for a Forth to have a Common Lisp like "condition handling" system?

Yes. The standard exception handling mechanism can do what the restart-case function does in Lisp.

: prompt-for-new-file ( -- sd.filename )
  s" Input new file name: " type pad dup 80 accept
;
: read-points-file ( sd.filename -- )
  ['] (read-points-file) catch dup 0= if exit then 2drop
  prompt-for-new-file recurse
;

Of course, some syntactic sugar can be also defined.