
Just making sure there isn’t some small-list optimization or something

There’s no small-list optimization.

@jubnzv has joined the channel

@howestim has joined the channel

@mavc has joined the channel

@sorawee Thanks! There isn’t a list equivalent to appending "" to a string, then, though?

What do you mean by that? You can do append
, right?
> (append (list 1) (list 2 3 4))
'(1 2 3 4)
> (append (list) (list 2 3 4))
'(2 3 4)

Ah, OK, so it is possible then. and I just shouldn’t have used cons.

Thanks

I worry sometimes when I play around with a new language to see what works, that I’m teaching myself “no, that approach doesn’t work” when really I just overlooked some basic error I made.

New question: Is there a good way to access internally defined functions? Like, for unit-testing, mostly.

By internally defined, you mean a function defined inside a function? Pretty sure the answer is no.

yeah

You can lambda-lift the function out, and then test it outside


Thanks, I’ll check it out!

Wow, that’s a lot of equations.

Is this, like, a programming technique, that they’re defining stringently to help in complicated cases, or does it detail how to program a function to automate your lambda-lifting for you?

For your use case, you might think of this as a kind of refactoring

I haven’t gotten into macros yet, but I could see there being a macro that takes a function name as input and then lambda-lifts its internally defined functions into the public scope.

(define (f x)
(define (g y)
(+ x y)
(g (+ 1 x))))
is converted to
(define (f x)
(define (g x* y)
(+ x* y)
(g x (+ 1 x))))
and then converted to
(define (g x* y)
(+ x* y)
(define (f x)
(g x (+ 1 x))))

I tend to define internal functions like the second case anyway, so actually lifting them out is easy; I just put them inside the functions where they’re used because I feel it’s tidier that way, and gives a better overview of the code.

I already lifted it out so I could unit-test it, but for aesthetic reasons, I’d like to put it back in and still be able to test it.

Eh, I guess it’s just one more item added on the pile of things I want to be able to do in the language I’m making…

That’s what module system is for

You can restrict what a module will export, so use that as a way to tidy your program.