Minimal foreign error API
Lassi Kortela
(28 Jul 2020 10:28 UTC)
|
Re: Minimal foreign error API
hga@xxxxxx
(28 Jul 2020 11:31 UTC)
|
Re: Minimal foreign error API
Lassi Kortela
(28 Jul 2020 12:05 UTC)
|
Re: Minimal foreign error API Lassi Kortela (28 Jul 2020 12:26 UTC)
|
Re: Minimal foreign error API
Lassi Kortela
(28 Jul 2020 12:30 UTC)
|
Re: Minimal foreign error API
Lassi Kortela
(28 Jul 2020 13:02 UTC)
|
Re: Minimal foreign error API
hga@xxxxxx
(28 Jul 2020 17:56 UTC)
|
Abstract or concrete data type for foreign error object?
Lassi Kortela
(31 Jul 2020 16:18 UTC)
|
Re: Abstract or concrete data type for foreign error object?
Shiro Kawai
(31 Jul 2020 18:29 UTC)
|
Re: Abstract or concrete data type for foreign error object?
hga@xxxxxx
(31 Jul 2020 19:04 UTC)
|
Re: Abstract or concrete data type for foreign error object?
Lassi Kortela
(01 Aug 2020 20:10 UTC)
|
Re: Minimal foreign error API
John Cowan
(28 Jul 2020 14:39 UTC)
|
Re: Minimal foreign error API
hga@xxxxxx
(28 Jul 2020 15:59 UTC)
|
Here's how you could let the caller know about the available languages: (define (plist-keys plist) (let loop ((plist plist) (keys '())) (if (and (pair? plist) (pair? (cdr plist))) (loop (cddr plist) (cons (car plist) keys)) (reverse keys)))) (define (make-translated-error . translations) (let ((languages (plist-keys translations)) (first-one (cadr translations))) (make-foreign-error 'languages languages 'message (case-lambda (() first-one) ((language) (plist-get/default translations language first-one)))))) (let ((e (make-translated-error 'en "Hello world" 'de "Hallo Welt" 'fi "Hei maailma"))) (disp (foreign-error-ref e 'message)) (disp (foreign-error-ref e 'languages)) (for-each (lambda (language) (disp (foreign-error-ref e 'message language))) (foreign-error-ref e 'languages))) ;; Output: Hello world (en de fi) Hello world Hallo Welt Hei maailma