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

Feature request: Placeholder operator #10

Open
arikheinss opened this issue Dec 25, 2023 · 0 comments
Open

Feature request: Placeholder operator #10

arikheinss opened this issue Dec 25, 2023 · 0 comments

Comments

@arikheinss
Copy link

Hello.

Over the last weeks, I ended up creating my own partial application package. One interesting feature I managed to implement that I think is pretty cool is a special "placeholder constant". It acts very similar to the _ in your @$-macro.

As an example, look at this:

greeter = println ¦ "Hello, " ¦ ⎵ ¦ ", nice to meet you!" 

greeter("bobby")
# ->Hello, bobby, nice to meet you!

greeter("peter", " Have a nice Day")
# ->Hello, peter, nice to meet you! Have a nice Day

The ¦ in my code has the same role as $ in your package. The is my placeholder constant, signifying that an argument should be supplied here.

If you want to implement this feature, one thing to consider is the name of this constant. Some suggestions:

  1. use (\underbracket) like I did. Advantages: expressive, the function of this is visually very obvious, unlikely to clash with other definitions made by the user/other packages loaded by the user. Disadvantage: People without IDE support (VSCode, Neovim, Jupyter) will have difficulty typing this character, as it is not part of any keyboard I know of.
  2. use something like _! (_ itself is not possible). Advantage: still somewhat expressive, sidesteps the problem from the last point. Disadvantage: pretty ugly!
  3. come up with something yourself...

The fact that there is a placeholder and its position should be accessible in the type signature, so code generation can make use of this and shuffle the arguments accordingly at compile time.

As in my last issue, I would supply this as a PR myself, but I am a bit short on time recently, and the way I have structured my package is quite a bit different to yours, so some adaptation is needed. I will give you a link to my code, if you want to do this you can use whatever you like from it, it is pretty simple and well documented. The relevant code is anything involving the type ReserveFunc. Anything past line 110 is just pretty printing and can be ignored.

Link: https://github.com/arikheinss/PartialApplication.jl/blob/main/src/PartialApplication.jl

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

1 participant