discussion icon indicating copy to clipboard operation
discussion copied to clipboard

Exception handling via a condition system : possible?

Open ghost opened this issue 2 years ago • 2 comments

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

ghost avatar Feb 15 '22 05:02 ghost

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.

MitchBradley avatar Feb 15 '22 06:02 MitchBradley

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.

ruv avatar Feb 22 '22 16:02 ruv