Is there something which takes a lambda which can be repeatedly applied to a value to get new values, such as next-collatz
, and sequentializes its output? (With or without a termination predicate)
Basically a sequentialize
For converting potentially opaque data types into sequences
So (sequentialize div10 1234567890)
@slack1 see in-producer
ah thanks!
@slack1 usually functions that don’t have an interesting return value produce (void)
I see
is it possible to not return anything?
including void?
you can return zero values using (values)
but what larger thing are you trying to accomplish?
well something like
(+ 1 2 3 (if condition? 4 <nothing>))
rather than 0
I know in that case you can do 0
But if you can do “nothing”, that is more general
I think the most practical answer is “no, you can’t do that”
though I once wrote a version of #%app
that I believe would make it possible http://pasterack.org/pastes/9185
When I put (values)
into DrRacket, nothing shows up in my repel
Could that be, in a sense, a “nothing” expression?
yes, (values)
is the expression that truly returns nothing at all
but it’s not very useful, because very few forms produce a continuation that can handle any number of values other than 1
if you do (+ 1 2 (values))
, you’ll get a runtime error because function application expects each of its subforms to be an expression that evaluates to exactly one value, no more and no less
the pasterack link I posted is an implementation of a macro that makes function application “splice” multiple values into the argument list, but I imagine it’s very slow.
(so I wouldn’t recommend actually using it.)
ah but macros run prior to compilation, right?
so they are basically free
yes, but that macro expands into an expensive runtime check.
so it isn’t free.
you could make it fast if you tracked at compile-time which expressions produced multiple values, using a type system for example. but Racket is obviously dynamically typed, so you have to do a runtime check to see how many values are produced by each expression.
and even then you probably couldn’t elide all the performance overhead of packing/unpacking multiple values. but it’d be a lot more efficient.
(and you wouldn’t suffer any performance hit for single-valued applications, which is the main reason the custom #%app
is a bad idea.)
ahh I see
Just wondering, do Haskellers ever use a similar idea of nothing?
no, every Haskell function both accepts and returns one and precisely one value.