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

Trouble with Implicit Parameters #39

Open
JoergWMittag opened this issue May 6, 2017 · 2 comments
Open

Trouble with Implicit Parameters #39

JoergWMittag opened this issue May 6, 2017 · 2 comments

Comments

@JoergWMittag
Copy link

I was toying around with Magpie's functional programming features and ran into some trouble with Implicit Parameters. I have a repository where I keep a simple implementation of the Church Encoding of lists in the λ-calculus in various languages and wanted to add a Magpie implementation.

Originally, I had written this:

val kons = fn(hd, tl) fn if _ then hd else tl
val virst = fn _ call(true )
val rrest = fn _ call(false)

val lstt  = kons call(1, kons call(2, nothing))

virst call(rrest call(lstt))

Which I thought should work (although I admit I didn't look into it too deeply), but I always get an error:

Uncaught NoVariableError: Could not find a variable named "_" (lambdaconscarcdr.mag (line 3, col 16-17)).

I am also befuddled by the fact that that the error appears on line 3, but not on the equivalent line 2. However, when I fix the error on line 3 by making the parameter explicit, it then reports line 1 as erroneous. When I fix that, the error moves to line 2.

The explicit version works:

val kons = fn(hd, tl) fn(x) if x then hd else tl
val virst = fn(l) l call(true )
val rrest = fn(l) l call(false)

val lstt  = kons call(1, kons call(2, nothing))

virst call(rrest call(lstt))

I am using the latest version of the Java interpreter at the moment, since the documentation says that the C++ VM is still missing some language features. (And also, I was lazy and I already had a Java environment set up anyway.)

@munificent
Copy link
Owner

The short answer is that I haven't touched Magpie in years, so it's probably a lost cause to try to write some working Magpie code at this point. :)

Could it maybe be related to not having an end for the if? I can't recall if Magpie allows eliding them for a single-line if statement.

@JoergWMittag
Copy link
Author

The short answer is that I haven't touched Magpie in years, so it's probably a lost cause to try to write some working Magpie code at this point. :)

Haha, okay, I'll take that answer.

Could it maybe be related to not having an end for the if? I can't recall if Magpie allows eliding them for a single-line if statement.

I don't think so. It works in the explicit version, after all, where all I do is replace the parameters and leave the rest of the code untouched, and there are several instances in the docs of one line ifs without end.

This is just a toy project. Don't sweat it.

I had written that code in Ruby, then wondered what it would look like in Python, then ECMAScript, and pretty soon I had written it in all languages I knew and then started writing it in languages I don't know, which is how I stumbled across such beauties as MISC, GOO, or Magpie.

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

2 participants