public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* Re: Using #!optional, #!rest, and #!key together
       [not found] <792B84DD-C6FA-4C57-9241-4FC0E59A9F3C@bothner.com>
@ 2017-04-23 19:24 ` Sudarshan S Chawathe
  2017-04-23 19:29   ` Per Bothner
  0 siblings, 1 reply; 3+ messages in thread
From: Sudarshan S Chawathe @ 2017-04-23 19:24 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

> I'm in a location with unexpectedly very bad connectivity. Check the
> invoke branch. It allows #!Rest *after* #!Key. See Application and
> arguments list in manual.

Thanks for the suggestion!  (I'm not sure why I switched back to master
from invoke a while back.)

I just switched over to the invoke branch and "rest after key" arguments
seems to work as expected (and also seems forgiving about ignoring extra
arguments).

The rest is just for completeness, in case it helps someone down the
road...

(define-syntax list/names
  (syntax-rules ()
    ((_ name ...) (list (cons 'name name) ...))))

(define test-args-2
  (lambda (a b #!optional c d #!key (f 'vf) (g 'vg) #!rest e)
    (list/names a b c d f g e)))

(test-args-2 1 2 3 4 f: 6 g: 7 5)
;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 6) (g . 7) (e 5))

(test-args-2 1 2 3 4 f: 7 g: 8 5 6)
;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 7) (g . 8) (e 5 6))

;; The next two are really errors.

(test-args-2 1 2 3 4 5 f: 6 g: 7)
;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 6) (g . 7) (e))

(test-args-2 1 2 3 4 5 6 f: 7 g: 8)
;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 7) (g . 8) (e))


Regards,

-chaw

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Using #!optional, #!rest, and #!key together
  2017-04-23 19:24 ` Using #!optional, #!rest, and #!key together Sudarshan S Chawathe
@ 2017-04-23 19:29   ` Per Bothner
  0 siblings, 0 replies; 3+ messages in thread
From: Per Bothner @ 2017-04-23 19:29 UTC (permalink / raw)
  To: Sudarshan S Chawathe; +Cc: kawa

On 04/23/2017 12:24 PM, Sudarshan S Chawathe wrote:
>> I'm in a location with unexpectedly very bad connectivity. Check the
>> invoke branch. It allows #!Rest *after* #!Key. See Application and
>> arguments list in manual.

[I have ok internet connectivity, again, for now.]

> Thanks for the suggestion!  (I'm not sure why I switched back to master
> from invoke a while back.)
> 
> I just switched over to the invoke branch and "rest after key" arguments
> seems to work as expected (and also seems forgiving about ignoring extra
> arguments).

> ;; The next two are really errors.
> 
> (test-args-2 1 2 3 4 5 f: 6 g: 7)
> ;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 6) (g . 7) (e))
> 
> (test-args-2 1 2 3 4 5 6 f: 7 g: 8)
> ;; => ((a . 1) (b . 2) (c . 3) (d . 4) (f . 7) (g . 8) (e))

I noticed that too.  That's a Kawa bug, that I hope to fix soon.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Using #!optional, #!rest, and #!key together
@ 2017-04-19 15:22 Sudarshan S Chawathe
  0 siblings, 0 replies; 3+ messages in thread
From: Sudarshan S Chawathe @ 2017-04-19 15:22 UTC (permalink / raw)
  To: kawa

Some background: I'd like to define a procedure that accepts a few
keyword-arguments as well as a variable number of non-keyword arguments
(both required and optional).  So, I'm looking at using #!optional,
#!rest, and #!key together but am confused by the specification.

Which brings me to my main, somewhat vague, question:

  1.   What is a good way to achieve the above (in Kawa)?  

My more specific questions follow.

  2. When a lambda uses #!key, my reading of the specification seems to
     require an even number of actual arguments following the
     required+optional actual arguments in a corresponding invocation,
     even if there is a #!rest. Is that really the case?

  3. To be even more specific, given

       (define (test-args a b #!optional c d #!rest e
                          #!key (f 'vf) (g 'vg))
         (list a b c d e f g))

     is it true that the first of the following is OK but the second is
     an error? 

       (test-args 1 2 3 4 5 6 f: 7 g: 8)

       (test-args 1 2 3 4 5 f: 6 g: 7)

Kawa doesn't flag an error (which is fine, I understand), but binds f
and g to 7 and 8 in the first case, and to their default values vf and
vg in the second case, so it does seem to treat them quite differently.

My confusion is probably not specific to Kawa, as the relevant text in
the manual is probably essentially from the DSSSL spec (based on similar
text in other manuals).  However, Chicken and Bigloo (just the ones I
looked at) seem to have implemented extensions that work around the
above issues and I'm trying to figure out a suitable strategy using
Kawa.

I'm guessing others have encountered similar situations and have some
good solutions, which I would love to hear.

Regards,

-chaw

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-23 19:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <792B84DD-C6FA-4C57-9241-4FC0E59A9F3C@bothner.com>
2017-04-23 19:24 ` Using #!optional, #!rest, and #!key together Sudarshan S Chawathe
2017-04-23 19:29   ` Per Bothner
2017-04-19 15:22 Sudarshan S Chawathe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).