[prev in list] [next in list] [prev in thread] [next in thread]
List: e-lang
Subject: Re: [e-lang] e.enable.pattern-default
From: "Mark S. Miller" <markm () caplet ! com>
Date: 2003-11-14 17:26:07
[Download RAW message or body]
At 08:32 AM 11/14/2003 Friday, Kevin Reid wrote:
> Does e.enable.pattern-default do what eprops.txt claims it does? I get a
> syntax error when I try to use the feature as described.
>
> ? ["no" => "value"] =~ ["key" else ("absent") => matched]
> # syntax error:
> # ["no" => "value"] =~ ["key" else ("absent") => matched]
> # ^
My mistake. I changed the syntax without updating the documentation in
eprops.txt. Try:
? pragma.enable("pattern-default")
? ["no" => "value"] =~ ["key" => matched := "absent"]
# value: false
I'm not happy with either the old or new syntax, so suggestions would be
great.
Reminder to all: Unless stated otherwise, language features that require a
"pragma.enable(...)" are experimental and not an official part of the E
language. There is no commitment that these features will continue to be
available or behave the same way from one release to the next. The purpose
of the pragma mechanism is to make available experimental features for us to
play with, so we can discuss what features to adopt based on experience.
Neither the old nor new syntaxes for the above feature have ever been an
official part of E. Their purpose is experimentation towards scope
manipulation for a better module system (about which more later), and for
keyword-based parameters:
? pragma.enable("pattern-default")
? pragma.enable("map-tail")
? def foo(i, "key" => matched := "absent") :String {
> ^matched + i
> }
# value: <foo>
? foo(3, "key" => "value", "foo" => "bar")
# value: "value3"
? foo(3, "foo" => "bar")
# value: "absent3"
Unlike (AFAIK) Python, keyword parameters would still not be supported by
Kernel-E as a primitive concept. The above expands as follows:
def foo(i, "key" => matched := "absent") :String {
^matched + i
}
expands to
def foo(i, ["key" => matched := "absent"]) :String {
^matched + i
}
The ["key" => matched := "absent"] pattern above in turn expands to
temp ? temp.extract("key", "absent") =~ [matched :any, _])
extract/2 is (too briefly) explained at
http://www.erights.org/javadoc/org/erights/e/elib/tables/EMap.html#extract(java.lang.Object,java.lang.Object)
The call
foo(3, "key" => "value", "foo" => "bar")
expands to
foo(3, ["key" => "value", "foo" => "bar"])
----------------------------------------
Text by me above is hereby placed in the public domain
Cheers,
--MarkM
_______________________________________________
e-lang mailing list
e-lang@mail.eros-os.org
http://www.eros-os.org/mailman/listinfo/e-lang
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic