Using condition types with psyntax

Asked by leppie

This is a possible solution for those wanting to make use of define-condition-type in psyntax. Most of the information was gathered from Ikarus and personal hacking.

NB: you need a working R6RS records implementation.

1. Add the 'condition-type-rtd' and 'condition-type-rcd' exports in the makefile/buildscript. This is a list similar to what you find in the Ikarus makefile. The reason these are here, is the names dont become mangled, and hence you can access the location via the symbol-value. These exports are not exported in any library.

2. Now create a library for you conditions as follows:
(library (foo conditions)
  (export ...) ; do not export the -rtd and -rcd symbols here (but this is where they are defined)
  (import ...)
    ;; implement the basic condition procedures here

    ;; the base condition class
    ;; you should check in make-record-type-descriptor for this name in case you need to derive from some internal Exception class (as I do in .NET)
    (define-record-type &condition (nongenerative))

    (define &condition-rtd (record-type-descriptor &condition))
    (define &condition-rcd (record-constructor-descriptor &condition))

    ;; now continue to add the condition types as defined in the R6RS lib spec

    (define-condition-type &message &condition
      make-message-condition message-condition?
      (message condition-message))
    ....

3. In the implementation of make-record-type-descriptor, you must set the -rtd with set-symbol-value!.

4. In the implementation of make-record-constructor-descriptor, you must set the -rcd with set-symbol-value!.

5. From the 'backend' you can simply access these types and constructors via symbol-value, and use them when needed.

Initially it looked a lot more complex, but it is rather easy if you have R6RS records in place. :)

Hope this helps someone.

Cheers

leppie

Question information

Language:
English Edit question
Status:
Solved
For:
r6rs-libraries Edit question
Assignee:
No assignee Edit question
Solved by:
leppie
Solved:
Last query:
Last reply:
Revision history for this message
leppie (leppie) said :
#1

.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) said :
#2

On Dec 20, 2007, at 8:18 AM, leppie wrote:

> 1. Add the 'condition-type-rtd' and 'condition-type-rcd' exports in
> the
> makefile/buildscript. This is a list similar to what you find in the
> Ikarus makefile. The reason these are here, is the names dont become
> mangled, and hence you can access the location via the symbol-value.
> These exports are not exported in any library.

There is more magic to it :-)

What you said is true. If you don't export them from any library, the
names don't get mangled. If you do export them from a library, then the
names do get mangled, but the expander will keep the mapping from the
names to the mangled counterpart. In Ikarus, these variables *are*
defined and exported in whatever library in ikarus.conditions.ss. Pretty
much every variable in Ikarus is defined in the library system and is
hidden (or mangled) so you cannot, for example, get to the procedure
cons by doing (symbol-value 'cons).

Revision history for this message
leppie (leppie) said :
#3

Thats good to know :)

Thanks

Revision history for this message
higepon(Taro Minowa) (higepon) said :
#4

Hi.
I use your psyntax for Mosh Scheme.(http://code.google.com/p/mosh-scheme/)
Thank you for your good library and this document.

define-condition-type works on Mosh with help of this document.

1. R6RS Records.
R6RS Records Procedural layer and Inspection are required.

2. mosh/condition.ss
Use IronScheme/IronSchemeConsole/ironscheme/conditions.ss for mosh/conditon.ss
Commented out &non-continuable and &implementation-restriction in export clause.
These two cause error when expanding.(Why?)

3.psyntax-buildscript-mosh.ss
(define scheme-library-files
  '("psyntax/compat.ss"
    "psyntax/internal.ss"
    "psyntax/config.ss"
    "psyntax/library-manager.ss"
    "psyntax/builders.ss"
    "psyntax/expander-mosh.ss"
    "../../r6rs-examples/mosh/condition.ss" ; Added
    "psyntax/main-mosh.ss"))

Added below to identifier->library-map
    (&condition-rtd)
    (&condition-rcd)
    (&message-rtd)
    (&message-rcd)
    (&warning-rtd)
    (&warning-rcd)
    (&serious-rtd)
    (&serious-rcd)
    (&error-rtd)
    (&error-rcd)
    (&violation-rtd)
    (&violation-rcd)
    (&assertion-rtd)
    (&assertion-rcd)
    (&irritants-rtd)
    (&irritants-rcd)
    (&who-rtd)
    (&who-rcd)
    (&non-continuable-rtd)
    (&non-continuable-rcd)
    (&implementation-restriction-rtd)
    (&implementation-restriction-rcd)
    (&lexical-rtd)
    (&lexical-rcd)
    (&syntax-rtd)
    (&syntax-rcd)
    (&undefined-rtd)
    (&undefined-rcd)
    (&i/o-rtd)
    (&i/o-rcd)
    (&i/o-read-rtd)
    (&i/o-read-rcd)
    (&i/o-write-rtd)
    (&i/o-write-rcd)
    (&i/o-invalid-position-rtd)
    (&i/o-invalid-position-rcd)
    (&i/o-filename-rtd)
    (&i/o-filename-rcd)
    (&i/o-file-protection-rtd)
    (&i/o-file-protection-rcd)
    (&i/o-file-is-read-only-rtd)
    (&i/o-file-is-read-only-rcd)
    (&i/o-file-already-exists-rtd)
    (&i/o-file-already-exists-rcd)
    (&i/o-file-does-not-exist-rtd)
    (&i/o-file-does-not-exist-rcd)
    (&i/o-port-rtd)
    (&i/o-port-rcd)
    (&i/o-decoding-rtd)
    (&i/o-decoding-rcd)
    (&i/o-encoding-rtd)
    (&i/o-encoding-rcd)
    (&no-infinities-rtd)
    (&no-infinities-rcd)
    (&no-nans-rtd)
    (&no-nans-rcd)

4. expand psyntax.pp!

5. In the implementation of make-record-type-descriptor, you must set the -rtd with set-symbol-value!
only when parent rtd is &conditon or subtype of &conditon.

6. In the implementation of make-record-constructor-descriptor, you must set the -rcd with set-symbol-value!.

Revision history for this message
leppie (leppie) said :
#5

> higepon(Taro Minowa) posted a new comment:
> 2. mosh/condition.ss
> Use IronScheme/IronSchemeConsole/ironscheme/conditions.ss for
> mosh/conditon.ss
> Commented out &non-continuable and &implementation-restriction in export
> clause.
> These two cause error when expanding.(Why?)

If I recall, I had a similar issue, maybe it was wrong/missing in the
buildscript.

Cheers

leppie

Revision history for this message
higepon(Taro Minowa) (higepon) said :
#6

Hi leppie!

You are right. Thank you.

+++ ../tools/psyntax-r6rs/psyntax-buildscript-mosh.ss 2008-08-07 23:58:20.000000000 +0900
@@ -130,8 +130,8 @@
     (&assertion ($core-rtd . (&assertion-rtd &assertion-rcd)))
     (&irritants ($core-rtd . (&irritants-rtd &irritants-rcd)))
     (&who ($core-rtd . (&who-rtd &who-rcd)))
- (&non ($core-rtd . (&non-continuable-rtd &non-continuable-rcd)))
- (&implementation ($core-rtd . (&implementation-restriction-rtd &implementation-restriction-rcd)))
+ (&non-continuable ($core-rtd . (&non-continuable-rtd &non-continuable-rcd)))
+ (&implementation-restriction ($core-rtd . (&implementation-restriction-rtd &implementation-restriction-rcd)))
     (&lexical ($core-rtd . (&lexical-rtd &lexical-rcd)))
     (&syntax ($core-rtd . (&syntax-rtd &syntax-rcd)))
     (&undefined ($core-rtd . (&undefined-rtd &undefined-rcd)))
sewashi%

Revision history for this message
higepon(Taro Minowa) (higepon) said :
#7

Hi.

I've posted a question about REPL at
https://answers.launchpad.net/r6rs-libraries/+question/43132

If you know something about it.
Will you please teach me?