[e-lang] Couple of newbie questions
Kevin Reid
kpreid at mac.com
Mon Dec 25 07:47:12 CST 2006
On Dec 25, 2006, at 0:39, Chris Rathman wrote:
> For example, the sine function would be invoked like:
>
> 0.5.sin()
>
> which from an OO perspective is impressive. But I couldn't figure
> out how to do this from an FP perspective short of wrapping it in a
> function (def _(x) { x.siu() }). Is there a way to use the methods
> as a function parameters short of wrapping them in a function? Not
> a big deal, but since it's fresh on my mind...
Not built-in. I've often thought that E ought to have a combinator
along these lines:
? pragma.syntax("0.9")
? def calls(verb :String) {
> return def callerFunc {
> to __printOn(tw :TextWriter) { tw.print(`calls($verb)`) }
> match [=="run", [rec] + args] { E.call(rec, verb, args) }}}
# value: <calls>
? def sin := calls("sin")
# value: calls(sin)
? sin(1.0)
# value: 0.8414709848078965
Once I have the E module system I have in mind written, I plan to
package up many utilities of this sort.
> 2). TCO: I don't know if the lack of tail call optimization is
> only in the Java implementation (I didn't try the Lisp version),
> but most FPers would likely complain about a lack of TCO.
E-on-CL inherits TCO from the underlying system.
> 3). Rune question: I couldn't figure out how to load a file from
> within the interpreter (opting to call Rune with the file as a
> parameter). Is there a "using" or "load" type command that can be
> issued from the interactive environment?
To run a file exactly as if from the command line, invoke 'rune' with
the arguments:
? rune(["/path/to/script.e", "arg"])
# ...
To run a file and also get the names it defines in your repl:
? def load(file) {
> def [v, s] := <elang:syntax.EParser>(file.getTwine()) \
> .evalToPair(interp.getTopScope())
> interp.setTopScope(s)
> return v
> }
# value: <load>
? load(<file:/path/to/script.e>)
# ...
> On the positive side:
>
> 1). Function/Expression Consistency: Many languages make a
> distinction between procedural constructs and expressions. The
> tell-tale is usually the if-then-else construct - and whether it
> can be used in an expression.
If you're interested, you can also write a non-special if
straightforwardly, using the boolean 'pick' method:
? true.pick(fn { println("ok") }, fn { println("not ok") })()
ok
> 2). Using Let: I couldn't see where E had a Let construct, but
> the lexical scoping and blocks {} are a cinch to work with.
> Section 1.3.2 is a fairly trivial example to demonstrate scoping in
> Scheme, but it is one of the harder ones I've found to express
> concisely among the languages that don't have a let construct.
> Mostly owing to #1 on consistency, I had no problems with it in E.
E's scope rules have a particularly unusual aspect: definitions may
be made deep within expressions.
? calls("run")(def list := [1,2,3,4,5,6,7,8,9],
> (def s := list.size()) // 3,
> s * 2 // 3)
# value: [4, 5, 6]
> I haven't looked at E's Lists just yet - (I'm hoping they lean
> towards the lists of Scheme, ML, Oz and Erlang - mostly because it
> makes the translation easier).
They do not. E's Lists are vectors (though we've discussed making
them ropes, transparently).
I plan to experiment with adding a linked list type obeying E's
collection protocols, but I haven't done so yet.
> Mark S. Miller wrote:
>> Chris Rathman wrote:
>>> SICP in E link: ...
I would prefer that you place (appropriately condensed) quoted text
above your reply.
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list