|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible <voi### [at] devnull> wrote:
> nemesis wrote:
>
> > I don't quite see your point. Scheme programmers have been doing it for decades
> > without static typing systems getting in the way. :)
>
> I don't know what Scheme is.
>
> People claim that Lisp is a functional language, but it doesn't look
> very functional to me. But Lisp apparently allows you to do something
> similar too... Whether it is "common" for Lisp programs to actually
> works like this is another matter. ;-)
Common Lisp is the "industrial-strength" Lisp idiom. It's basically a mix of
several old Lisps with a bit of Scheme. Scheme is a minimalist Lisp idiom
designed mainly for research and education. The many implementations make sure
it's able to do a lot more.
Old Lispers are indeed pretty imperative but Scheme is a strict, eager
evaluation, mostly functional language which solves problems mostly by function
application and applicative programming. Mutators (set!) and direct
side-effecting IO are still present, but using sparingly. It's very much like
ML, except with sweet regular syntax, no builtin pattern matching and no static
typing. Of course, you may probably don't know what ML is, but Google is your
friend. You may eventually learn about Haskell's ancestry...
Here's an example of Scheme code:
(let ((%? (lambda (a b) (zero? (modulo a b)))))
(let sum ((i 5) (r 0))
(if (= i 100000) r
(sum (+ 1 i) (if (or (%? i 5) (%? i 7))
(+ r i)
r)))))
Forget the parentheses. Besides all, they are a great aid for structured
editing of source code in appropriate editors, like replacing a whole large
parenthetical expression in a breeze.
You could try downloading
http://download.plt-scheme.org/drscheme/
And running it. Not necessarily the fastest Scheme implementation (that would
be the Stalin native compiler), but a very complete and sound all-around
implementation and friendly programming environment.
BTW, you seem to enjoy math and programming and since there are so many things
you don't know, perhaps this is a good opportunity for showing you this?
http://projecteuler.net/
It's a very popular, friendly, free-time contest of math/programming problems.
Register, pick a favorite language, enter the correct answer to the problems
and eventually become an Eulerian:
http://projecteuler.net/index.php?section=scores&show=eulerians
It's very fun. The statistics page is a finding... :)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> BTW, you seem to enjoy math and programming and since there are so many
> things
> you don't know, perhaps this is a good opportunity for showing you this?
>
> http://projecteuler.net/
Hehe, did you look in p.o-t.f.h.b.b.b ?
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis wrote:
> BTW, you seem to enjoy math and programming and since there are so many things
> you don't know, perhaps this is a good opportunity for showing you this?
>
> http://projecteuler.net/
As Scott said - it's on that other newsgroup. I don't know if it's been
discussed in a while, though.
I did about 100 problems. Would like to get back to them, but they tend
to eat up my hours.
--
Vultures only fly with carrion luggage.
/\ /\ /\ /
/ \/ \ u e e n / \/ a w a z
>>>>>>mue### [at] nawazorg<<<<<<
anl
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
scott wrote:
>> BTW, you seem to enjoy math and programming and since there are so
>> many things
>> you don't know, perhaps this is a good opportunity for showing you this?
>>
>> http://projecteuler.net/
>
> Hehe, did you look in p.o-t.f.h.b.b.b ?
>
Now I see. I should've known Mathematical Orchid would know it better. :)
Well, I won't be looking at the ones I didn't do yet, spoils all the fun. :P
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis wrote:
> Common Lisp is the "industrial-strength" Lisp idiom. It's basically a mix of
> several old Lisps with a bit of Scheme. Scheme is a minimalist Lisp idiom
> designed mainly for research and education. The many implementations make sure
> it's able to do a lot more.
>
> Old Lispers are indeed pretty imperative but Scheme is a strict, eager
> evaluation, mostly functional language which solves problems mostly by function
> application and applicative programming. Mutators (set!) and direct
> side-effecting IO are still present, but using sparingly. It's very much like
> ML, except with sweet regular syntax, no builtin pattern matching and no static
> typing. Of course, you may probably don't know what ML is, but Google is your
> friend.
ML I have at least heard of. The vague impression I have is that it's
kind of similar to Haskell, but insane.
> You may eventually learn about Haskell's ancestry...
AFAIK, Haskell is basically Miranda(tm) with a few minor modifications.
(Oh, and type classes.)
> Here's an example of Scheme code:
> (let ((%? (lambda (a b) (zero? (modulo a b)))))
> (let sum ((i 5) (r 0))
> (if (= i 100000) r
> (sum (+ 1 i) (if (or (%? i 5) (%? i 7))
> (+ r i)
> r)))))
>
> Forget the parentheses. Besides all, they are a great aid for structured
> editing of source code in appropriate editors, like replacing a whole large
> parenthetical expression in a breeze.
I think you'd need to colour code expressions by depth or something to
really make sense of that. Really deeply nested expressions are
difficult to parse visually. (I also imagine that without assistence it
would be very hard to make all the parentheses match up correctly...)
> BTW, you seem to enjoy math and programming and since there are so many things
> you don't know, perhaps this is a good opportunity for showing you this?
>
> http://projecteuler.net/
I did a few of them, but the later ones are too hard. (And, frankly, not
very interesting.)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible wrote:
> nemesis wrote:
> ML I have at least heard of. The vague impression I have is that it's
> kind of similar to Haskell, but insane.
They both look insane to me. ;)
>> You may eventually learn about Haskell's ancestry...
>
> AFAIK, Haskell is basically Miranda(tm) with a few minor modifications.
> (Oh, and type classes.)
Yes, but ML was the one to really begin it all. OCaml is it's current
popular iteration, as well as F# from Microsoft.
>> Here's an example of Scheme code:
>> (let ((%? (lambda (a b) (zero? (modulo a b)))))
>> (let sum ((i 5) (r 0))
>> (if (= i 100000) r
>> (sum (+ 1 i) (if (or (%? i 5) (%? i 7))
>> (+ r i)
>> r)))))
> I think you'd need to colour code expressions by depth or something to
> really make sense of that. Really deeply nested expressions are
> difficult to parse visually.
Not at all. Prefix syntax makes everything very clear: most everything
in the begining of a list is a function or macro and the rest are
arguments, like
(+ 1 i) or ((lambda (x) (* x x)) 3)
Identifiers can have symbols like "?".
> (I also imagine that without assistence it
> would be very hard to make all the parentheses match up correctly...)
Not at all, if notepad is all you got, just be sure to always open and
close in sequence, then position between and continue typing. Of
course, I won't comment on identation in this case. :D
But any slightly advanced editor gives you parentheses matching for free.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
nemesis wrote:
> They both look insane to me. ;)
OK, fair enough.
>>> You may eventually learn about Haskell's ancestry...
>>
>> AFAIK, Haskell is basically Miranda(tm) with a few minor
>> modifications. (Oh, and type classes.)
>
> Yes, but ML was the one to really begin it all. OCaml is it's current
> popular iteration, as well as F# from Microsoft.
I haven't really looked at OCaml.
I looked at Clean. (It isn't.) And also F# (which seemed really ugly).
>> I think you'd need to colour code expressions by depth or something to
>> really make sense of that. Really deeply nested expressions are
>> difficult to parse visually.
>
> Not at all. Prefix syntax makes everything very clear: most everything
> in the begining of a list is a function or macro and the rest are
> arguments, like
> (+ 1 i) or ((lambda (x) (* x x)) 3)
I'm having trouble seeing which thing a given subexpression is the
argument to. To do that, you have to count brackets. It's not
impossible, just not very easy.
>> (I also imagine that without assistence it would be very hard to make
>> all the parentheses match up correctly...)
>
> Not at all, if notepad is all you got, just be sure to always open and
> close in sequence, then position between and continue typing. Of
> course, I won't comment on identation in this case. :D
>
> But any slightly advanced editor gives you parentheses matching for free.
SciTE gives me paren matching, but apparently it doesn't understand
Haskell syntax, so it fails to comprehend that anything inside quote
marks is a literal string and so shouldn't be matched against... :-S
Maybe I should go write a text editor of my own...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Invisible escreveu:
> nemesis wrote:
>> Not at all. Prefix syntax makes everything very clear: most
>> everything in the begining of a list is a function or macro and the
>> rest are arguments, like
>> (+ 1 i) or ((lambda (x) (* x x)) 3)
>
> I'm having trouble seeing which thing a given subexpression is the
> argument to. To do that, you have to count brackets. It's not
> impossible, just not very easy.
Lispers just forget the parentheses and look at the indented code.
Parentheses are only important for macros and structured editing.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
>>> (+ 1 i) or ((lambda (x) (* x x)) 3)
>>
>> I'm having trouble seeing which thing a given subexpression is the
>> argument to. To do that, you have to count brackets. It's not
>> impossible, just not very easy.
>
> Lispers just forget the parentheses and look at the indented code.
> Parentheses are only important for macros and structured editing.
Well, if you already know how many parameters each function takes, that
could work. It still doesn't help when multiple parameterisations are
valid though...
(Also, the example you mosted has some fairly unhelpful indentation in it.)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Orchid XP v8 wrote:
> Well, if you already know how many parameters each function takes, that
> could work.
In the example I gave, all functions are known, because they are locally
defined. Other than that:
*lambda* creates a new function by taking a list of parameters and
several subexpressions as body => (lambda (p1 p2 ...) body ...)
*let* takes a list of local bindings and then may have several
subexpressions as body => (let ((b1 v1) (b2 v2) ...) body ...)
let is just a macro for ((lambda (b1 b2 ...) body ...) v1 v2 ...)
That is, the application of values to the function. :)
*if* takes a condition and has at least one branch => (if foo this) or
(if foo this that)
*or* takes several subexpressions and evaluates them with logical or
=> (or foo bar ...)
> (Also, the example you mosted has some fairly unhelpful indentation in it.)
BTW, it's problem 1 from Euler, except twisted a bit. I didn't know you
already knew of it. :P
(let ((%? (lambda (a b) (zero? (modulo a b)))))
(let sum ((i 5) (r 0))
(if (= i 100000) r
(sum (+ 1 i) (if (or (%? i 5) (%? i 7))
(+ r i)
r)))))
I don't think it's particularly bad indented. In named lets, I tend to
call it like a function, all parameters in the same line. Lisp
indenting generally puts only the first parameter in the same line, the
others go below, indented at the same line as the first parameter.
Anyway, it reads like this:
> (let ((%? (lambda (a b) (zero? (modulo a b)))))
let %? be a function taking a b as arguments and saying if a is
divisible by b
> (let sum ((i 5) (r 0))
then let sum be a function taking (i initially 5) and (r initially 0)
> (if (= i 100000) r
and returning r if i == 100000
> (sum (+ 1 i) (if (or (%? i 5) (%? i 7))
> (+ r i)
> r)))))
or sum of (incremented i) and ((r+i) -- if i divisible by 5 or by 7 --
(or r otherwise))
Is it really that hard? Perhaps I've lost my mind in parentheses and
can now see clearly through the Matrix code stream... :D
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|