how the second argument to ERROR is handled

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how the second argument to ERROR is handled

Marco Maggi-2
Ciao,

  with CHICKEN 5.1.0, is the following correct:

      (import (scheme) (chicken base) (chicken condition))

      (call/cc
          (lambda (escape)
            (with-exception-handler
                (lambda (E)
                  (escape (list (get-condition-property E 'exn 'location)
                                (get-condition-property E 'exn 'message)
                                (get-condition-property E 'exn 'arguments))))
              (lambda ()
                (error 1 2 3)))))
      => '(#f 1 (2 3))

or should the "message" property be #f?

TIA
--
Marco Maggi

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users
Reply | Threaded
Open this post in threaded view
|

Re: how the second argument to ERROR is handled

Peter Bex
On Sun, Jul 21, 2019 at 09:03:33AM +0200, Marco Maggi wrote:

> Ciao,
>
>   with CHICKEN 5.1.0, is the following correct:
>
>       (import (scheme) (chicken base) (chicken condition))
>
>       (call/cc
>           (lambda (escape)
>             (with-exception-handler
>                 (lambda (E)
>                   (escape (list (get-condition-property E 'exn 'location)
>                                 (get-condition-property E 'exn 'message)
>                                 (get-condition-property E 'exn 'arguments))))
>               (lambda ()
>                 (error 1 2 3)))))
>       => '(#f 1 (2 3))
>
> or should the "message" property be #f?
Hi Marco,

This looks fine to me.  The first argument to "error" should always
be the message.  You could argue that it should check for it to be
a string, but I'm not sure that's required.

The docs seem to suggest that the reason string is optional.  I think
this is wrong.

Cheers,
Peter

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users

signature.asc (499 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: how the second argument to ERROR is handled

megane

Peter Bex <[hidden email]> writes:

> On Sun, Jul 21, 2019 at 09:03:33AM +0200, Marco Maggi wrote:
>> Ciao,
>>
>>   with CHICKEN 5.1.0, is the following correct:
>>
>>       (import (scheme) (chicken base) (chicken condition))
>>
>>       (call/cc
>>           (lambda (escape)
>>             (with-exception-handler
>>                 (lambda (E)
>>                   (escape (list (get-condition-property E 'exn 'location)
>>                                 (get-condition-property E 'exn 'message)
>>                                 (get-condition-property E 'exn 'arguments))))
>>               (lambda ()
>>                 (error 1 2 3)))))
>>       => '(#f 1 (2 3))
>>
>> or should the "message" property be #f?
>
> Hi Marco,
>
> This looks fine to me.  The first argument to "error" should always
> be the message.  You could argue that it should check for it to be
> a string, but I'm not sure that's required.
>
> The docs seem to suggest that the reason string is optional.  I think
> this is wrong.
>

The first argument is handled differently if it's a symbol:

(condition-case (error 'foo "bar" "baz")
  [exn () (pp (alist-update 'call-chain 'xxx (cdar (condition->list
  exn))))])

;; ((location foo) (call-chain . xxx) (arguments ("baz")) (message "bar"))

(condition-case (error "foo" "bar" "baz")
  [exn () (pp (alist-update 'call-chain 'xxx (cdar (condition->list
  exn))))])

;; ((location #f) (call-chain . xxx) (arguments ("bar" "baz")) (message "foo"))

_______________________________________________
Chicken-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/chicken-users