Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have with-output-to-string and friends take a body, not a thunk. #54

Open
gus-massa opened this issue Jul 21, 2019 · 5 comments
Open

Have with-output-to-string and friends take a body, not a thunk. #54

gus-massa opened this issue Jul 21, 2019 · 5 comments

Comments

@gus-massa
Copy link

  • Have with-output-to-string and friends take a body, not a thunk. The current form is better named call-with-output-to-string, in the general pattern of with-x being syntax and call-with-x being a procedure.

Extracted from the old racket2 wiki. #33

More generally, is it good to keep the with-x and call-with-x forms?

Tangentially discussed in #49

@johnwcowan
Copy link

Better, have a general way to turn thunky procedures into body-bearing syntax, like Ruby's trick of putting a lambda immediately after the function call rather than before.

@gus-massa
Copy link
Author

Can you give an example of the trick in Ruby?

@johnwcowan
Copy link

johnwcowan commented Oct 8, 2019

In Ruby, instead of writing my_procedure(a, b, c, {|x, y| do_something(x, y)}) where braces surround a lambda and vertical bars surround its arguments), you write:

my_procedure(a, b, c) {
  |x, y| do_something (x, y)
}

which makes my_procedure look like syntax. You can prepend lambda or proc (with a slight difference in semantics) to the {} construction in order to make it an ordinary value.

Note that in Smalltalk, the ancestor of Ruby, if is theoretically a method, not syntax: you write it (using Scheme syntax here as more familiar) as
(if-then-else p (lambda () something1 ) (lambda () something2), and it works because of method dispatch: the Boolean class has subclasses True and False with different definitions of if-then-else. The bytecode compiler will optimize the lambdas away, turning them into jumps. It may or may not work to put your own definition on other classes to make their objects truthy or falsy.

@jackfirth
Copy link
Sponsor Collaborator

So, supposing an S-expression-like syntax, maybe an #%app macro where this:

(function arg ... { body ... })

Is short for this:

(function arg ... (lambda () body ...))

But I'm not sure how to add arguments to the lambda without making it messier in the common case of simple thunks.

@johnwcowan
Copy link

In Ruby and Smalltalk the |...| argument syntax is optional. We don't want to use actual vertical bars, but we could write {[x y] body}, where [x y] is optional. It depends on how much the Rhombus syntax actually changes Scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants