Continuations: The Swiss Army Knife of Flow Control
Вставка
- Опубліковано 16 лип 2024
- In this talk, we are discussing a programming construct called "continuations," which essentially allow points in your program to be saved and returned to at a later point. We are also discussing the many different flow control operators that can be built from this tool, including exception handling, multithreading, and logic programming.
- Наука та технологія
this deserves more views. thank you.
This talk is really eye opening. Thank you
It'd be nice if you would do a tour of what delimited continuations are and what advantages they offer
Great video; thanks for helping us humble programmers get to a better understanding of continuations!
It’s a bit confusing in some places, though, when you say “stack frame,” and you are actually talking about the entire stack.
That is minor, keep doing what you are doing; fantastic stuff, good work!
This was a great talk 👍
2:33 - The order the sub-expressions are evaluated (i.e. executed) is undefined, but the order of the values of these sub-expressions is defined.
(f (g) (h))
might run "g" first or might run "h" first, but the value of the application (i.e. execution) of the procedure "g" (i.e. "(g)") will always be the first argument, and "(h)" will always be the second argument to the application of the function "f".
cool explanation. this guy has probably mentioned this book: "Essentials of Programming Languages" by D. Friedman and M. Wand, 3rd ed.
Thanks that's what I wanted to ask in comments
This is great but why would you animate a stack going down?? Sorry for nitpicking but the visual metaphor is kind of an important piece to understanding stacks. Anyway good talk regardless.
True, but, honestly, stacks usually grow downward. Memory allocations grow from the bottom of memory up, stacks usually grow from the top of memory down (though, in Scheme, not all implementations use a hardware stack). Additionally, in the visual, it makes them both start nearby each other :)
What is wrong with you two? Memory is horizontal 😑
ngl, I kinda hate the (define foo (lambda x ...)) style some schemers write, why not just do the shorter (define (foo x) ...) instead?
When I'm teaching I often like to separate out different parts of constructions rather than using shortcuts. It helps students recognize the difference between creating a function and defining the meaning of a symbol, and helps them recognize that, in Scheme, there is nothing special about assigning a function vs. any other kind of value.
@@BPLearningTV It's not really a shortcut though. Every programming language separates the function creation syntax from the variable creation syntax; saying one is how you define a function and one is how you define a variable isn't really very confusing and may in fact help students when moving to other languages.
Heck, even Haskell and OCaml which both also have a similar approach to Scheme regarding the visual difference between values and functions don't have teachers bend over backwards to prefer
let f = fun x -> foo x
instead of just writing
let f x = foo x
even though both effectively give you the same result.
Let functions be functions and variables be variables. It's not any more confusing to a student to say both of them define a new symbol.
@@NikolajLepka Students often fail to recognize when they are defined differently that they play in the same namespace, and both represent values. Treating a function as a value is in fact something that new students have trouble with, and separating the function creation syntax from the assignment syntax makes this more clear.
Showing it without the syntactic sugar gives a good foundation for what's actually going on before they start using that syntactic sugar. He's also stressing the symbolic nature of Scheme. You don't just create a toplevel function and it magically gets stored somewhere - you need it to be bound to a symbol which is what the long hand form demonstrates.
@@NikolajLepka Continuation work because in scheme variable and function definitions share the same space.
If you do it in common lisp, you will get an error that your collector function which you defined as a variable in the argument list, is an undefined function, as you have not defined it as a function.
To get around this, you will have to use funcall whenever you use the collector function in the main function definition
It’s like JavaScript ;) This is all nice, but what is the performance like?
JavaScript was a scheme first. It got Java and C-ified in syntax
There is no such word "parenthesee". The singular form of parentheses is parenthesis, not parenthesee.