Allowing unspecified key arguments in functions

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

Allowing unspecified key arguments in functions

Amir Teymuri
I had a question about the objectives and reasons of allowing
un-specified key arguments in functions as soon as i want to have some
key arguments. Take a look at the following case:

;;; The function
(define (foo a #!key b) (list a b))

Now passing any number of key arguments in addition to b doesn't
result in any error which makes the debugging of even some simple
typing errors very difficult in a large code:

(define (foo a #!key b) (list a b))
(foo 2) ; ===> (2 #f)
(foo 2 #:b 3) ; ===> (2 3)
(foo 2 #:b 3 #:c 4 #:d 5 #:e 6) ; ===> (2 3)

without any errors!  Why is this and what was the reasons of deciding
this too much freedom?

Regards,
Amir

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

Re: [Chicken-hackers] Allowing unspecified key arguments in functions

Kooda
Amir Teymuri <[hidden email]> wrote:
> I had a question about the objectives and reasons of allowing
> un-specified key arguments in functions as soon as i want to have some
> key arguments.

Any DSSSL style arguments (#!rest, #!optional and #!key) always are
optional arguments to the procedure.

You can think of them as working this way:

(lambda (foo #!key bar qux) your-code)
=>
(lambda (foo . rest)
  (let ((bar (get-keyword-arg #:bar rest))
        (qux (get-keyword-arg #:qux rest)))
    your-code))

If you want to have a more strict handling of them, you might want to
write your own superset of “lambda” and/or “define”, that check
what you need.

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