Re: [racket-users] Reflecting on context arity

2020-03-28 Thread Laurent
Follow up on Ben's idea:
Take n as an optional argument, init value #f.
On first application of f on the first values, continue n-map with
n=received number of values. Once arrived at the empty lists you know how
many values you should have.
At each iteration, you can even check that the number of values doesn't
change (or take the max?).

The only corner case is when provided with empty lists from the start, in
which case either the user can specify the init value for n if it is known,
or you can throw an exception.


On Sat, Mar 28, 2020, 00:40 Ben Greenman 
wrote:

> procedure-result-arity is very limited
>
> if you can find a way to call `f` once, though, you could assume that
> its result arity never changes
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAFUu9R6YDx9%2BF27dHW3N1P%3DMK_UuzfrWqo01kigM4fBKxxFXUA%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABNTSaEPkeTeMOS_wv9t774mVcBAbE5pqa4aaRfdvRXkCqRDCA%40mail.gmail.com.


Re: [racket-users] Reflecting on context arity

2020-03-27 Thread Ben Greenman
procedure-result-arity is very limited

if you can find a way to call `f` once, though, you could assume that
its result arity never changes

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAFUu9R6YDx9%2BF27dHW3N1P%3DMK_UuzfrWqo01kigM4fBKxxFXUA%40mail.gmail.com.


[racket-users] Reflecting on context arity

2020-03-27 Thread William J. Bowman
I'm trying to write a generalization of map that supports multiple return
values:

(define (map-n n f ls . lss)
  (if (empty? ls)
  (apply values (build-list n (lambda _ '(
  (call-with-values
   (thunk (apply f (car ls) (map car lss)))
   (lambda vs
 (call-with-values
  (thunk (apply map-n n f (cdr ls) (map cdr lss)))
  (lambda lss
(apply
 values
 (map cons vs lss

This version works fine, but, tediously, requires I specify how many return
values.
This is annoying, since surely the context knows how many values it expects:

> (let/ec escape
(let-values ([(a b c)
  (let/cc k
(escape (procedure-arity k)))])
  'meow))
> (arity-at-least 0)

Oh, I guess not.
Well that's fine, because surely I can reflect on `f`'s result arity:

> (procedure-result-arity (lambda (x) (values 'a 'b 'c)))
> #f

Welp.

So, uh, can I haz a current-context-arity please?

-- 
William J. Bowman

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/20200328002810.GN31619%40williamjbowman.com.