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

Using procedures in functions #613

Open
Goju-Ryu opened this issue Oct 10, 2024 · 3 comments
Open

Using procedures in functions #613

Goju-Ryu opened this issue Oct 10, 2024 · 3 comments

Comments

@Goju-Ryu
Copy link
Contributor

I found myself wishing to be able to call procedures inside a function today. My use case was to set up the arguments of an assert I planned to run in many different variations. I wanted to test mys implementation of human against the existing one and thought I'd write something like the following:

fn test_human(time: Time) = assert_eq(time -> human, time -> human_new)

fn test_human_range(times: List<Time>) = times |> map(test_human)

I think it would be very beneficial for testing if something like the first line at least was possible. The second line is probably a lot more involved, so I won't focus too much on it.

I imagine it might be difficult or undesirable to mix functions and procedures, in which case I would instead propose to introduce custom procedures, a function-like construct that can only call other procedures.

@sharkdp
Copy link
Owner

sharkdp commented Oct 23, 2024

I found myself wishing to be able to call procedures inside a function today.

Yes, I can understand the pain. I also wanted something like this in the past.

On the other hand, that would complicate the language / type system a lot, I'm afraid. For now, function bodys are simply expressions. With your suggestion, we would allow (arbitrary) statements in the function body.

I imagine it might be difficult or undesirable to mix functions and procedures

Right.

in which case I would instead propose to introduce custom procedures, a function-like construct that can only call other procedures.

… or dare I say ... a macro? 😄

Let's think about it!

@Goju-Ryu
Copy link
Contributor Author

I didn't even think about what I described in the end was basically just a macro. I would love for numbat to have a good macro system, but I think it takes quite a bit more thought than I originally imagined.
For now, should I change the title and update the description to reflect that the issue will be about implementing macros?

@sharkdp
Copy link
Owner

sharkdp commented Oct 23, 2024

For now, should I change the title and update the description to reflect that the issue will be about implementing macros?

Macros would be one way to support your use case. Let's also think about other ways. The title of the ticket is good as it is, thanks.

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

No branches or pull requests

2 participants