slack1
2017-12-10 18:54:18

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)


slack1
2017-12-10 18:54:28

Basically a sequentialize


slack1
2017-12-10 18:54:49

For converting potentially opaque data types into sequences


slack1
2017-12-10 18:56:02

So (sequentialize div10 1234567890)


samth
2017-12-10 18:56:41

@slack1 see in-producer


slack1
2017-12-10 18:58:01

ah thanks!


samth
2017-12-10 19:50:12

@slack1 usually functions that don’t have an interesting return value produce (void)


slack1
2017-12-10 19:50:30

I see


slack1
2017-12-10 19:50:35

is it possible to not return anything?


slack1
2017-12-10 19:50:41

including void?


samth
2017-12-10 19:51:37

you can return zero values using (values)


samth
2017-12-10 19:51:48

but what larger thing are you trying to accomplish?


slack1
2017-12-10 19:52:52

well something like


slack1
2017-12-10 19:53:20

(+ 1 2 3 (if condition? 4 <nothing>))


slack1
2017-12-10 19:53:40

rather than 0


slack1
2017-12-10 19:53:47

I know in that case you can do 0


slack1
2017-12-10 19:53:54

But if you can do “nothing”, that is more general


lexi.lambda
2017-12-10 19:54:55

I think the most practical answer is “no, you can’t do that”


lexi.lambda
2017-12-10 19:55:12

though I once wrote a version of #%app that I believe would make it possible http://pasterack.org/pastes/9185


slack1
2017-12-10 19:56:03

When I put (values) into DrRacket, nothing shows up in my repel


slack1
2017-12-10 19:56:25

Could that be, in a sense, a “nothing” expression?


lexi.lambda
2017-12-10 19:56:53

yes, (values) is the expression that truly returns nothing at all


lexi.lambda
2017-12-10 19:57:10

but it’s not very useful, because very few forms produce a continuation that can handle any number of values other than 1


lexi.lambda
2017-12-10 19:57:54

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


lexi.lambda
2017-12-10 19:58:35

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.


lexi.lambda
2017-12-10 19:58:47

(so I wouldn’t recommend actually using it.)


slack1
2017-12-10 19:59:15

ah but macros run prior to compilation, right?


slack1
2017-12-10 19:59:18

so they are basically free


lexi.lambda
2017-12-10 19:59:28

yes, but that macro expands into an expensive runtime check.


lexi.lambda
2017-12-10 19:59:32

so it isn’t free.


lexi.lambda
2017-12-10 20:00:38

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.


lexi.lambda
2017-12-10 20:01:15

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.


lexi.lambda
2017-12-10 20:01:46

(and you wouldn’t suffer any performance hit for single-valued applications, which is the main reason the custom #%app is a bad idea.)


slack1
2017-12-10 20:07:24

ahh I see


slack1
2017-12-10 20:07:48

Just wondering, do Haskellers ever use a similar idea of nothing?


lexi.lambda
2017-12-10 20:09:58

no, every Haskell function both accepts and returns one and precisely one value.