Lazy evaluation

T

ts

F> What's the difference between P and R language in this case then if it
F> is not that a feature should try to solve concrete problems?

You think, apparently, that it exist a concrete problem and you think that
you can, or need to, to solve it.

Personnaly I don't know :)


Guy Decoux
 
F

Florian Gross

ts said:
F> What's the difference between P and R language in this case then if it
F> is not that a feature should try to solve concrete problems?

You think, apparently, that it exist a concrete problem and you think that
you can, or need to, to solve it.

No. As I said: I'm providing, not solving. I do the same that Ruby does
with callcc. And Ruby is no P language, as you said.

Regards,
Florian Gross
 
K

Kristof Bastiaensen

So Ruby is a P language because it has callcc?

From a conceptual point of view is callcc very important.
It is not just added because it may seem like a good feature,
but because it makes Ruby a real functional language (like scheme).
In functional languages can continuations be seen as a
functions-calls.
I find one of the great things about Ruby, how it combines
both object oriented programming (smalltalk) and functional
programming (scheme) in such an elegant way.
 
G

gabriele renzi

il Sat, 01 May 2004 12:29:59 +0200, Kristof Bastiaensen
From a conceptual point of view is callcc very important.
It is not just added because it may seem like a good feature,
but because it makes Ruby a real functional language (like scheme).

I think this sentence may be incorrect.
I mean, haskell, ocaml and lisp all does not have call/cc yet they're
functional languages.
(actually I'm not sure if lisp, ocaml and scheme can be defined as
functional languages, cause they're not pure ones, if I'm correct)
 
S

Simon Strandgaard

Lionel Thiry said:
Simon Strandgaard a écrit :
Solving and Proving, as I could understand.
And R is Ruby I suppose.

There are lots of combinations..

P = Proving/Python/Perl/Prolog/Pascal
R = Ruby/Rebol/Rlang
S = Solving/Scheme/Smalltalk/Slang/SML

Im affraid I still don't understand this thread.
 
L

Lionel Thiry

gabriele renzi a écrit :
il Sat, 01 May 2004 12:29:59 +0200, Kristof Bastiaensen
<[email protected]> ha scritto::






I think this sentence may be incorrect.
I mean, haskell, ocaml and lisp all does not have call/cc yet they're
functional languages.
(actually I'm not sure if lisp, ocaml and scheme can be defined as
functional languages, cause they're not pure ones, if I'm correct)
Ocaml is a functionnal langage of the ML family. It means it abuses of
pattern matching and allows for side effects. As far as I know, lisp and
scheme are pure functionnal langage as they don't allow side effects.
But perhaps I'm wrong. And I'm often wrong. ;)

About Ruby, I must tell I find it hard to see where Ruby is functionnal
langage. Coding recursivity in ruby is most of the time so uneasy. I
just wonder, if someone can explain, he'll be welcome.

Lio
 
L

Lionel Thiry

Simon Strandgaard a écrit :
There are lots of combinations..

P = Proving/Python/Perl/Prolog/Pascal
R = Ruby/Rebol/Rlang
S = Solving/Scheme/Smalltalk/Slang/SML

Im affraid I still don't understand this thread.
I don't understand it either! ;)

Perhaps it is about the P programming langage?
http://blrc.edu.cn/research/P/header.htm

And about the S programming langage?
http://cm.bell-labs.com/cm/ms/departments/sia/Sbook/

Or about some exotic way to classify langages? If someone could light up...

Lio
 
D

Dan Doel

Lisp is more or less the original functional language. However, it's pretty
multi-paradigm, as you can do procedural or even object oriented (and logic?)
programming with it. It's just not a pure functional language like Haskell.
Same with Scheme and OCaml. They just encourage programming in a functional
style (Scheme and OCaml more so than Lisp, maybe).

I'd say lambda expressions are more of a defining characteristic of functional
languages.

call/cc is an important function, conceptually, though, since with it you can
implement arbitrary control flow constructs (like conditionals and loops). So
when people ask for things like resumable exceptions, we can do them in pure
Ruby. :)

- Dan
 
S

Simon Strandgaard

Lionel Thiry said:
Ocaml is a functionnal langage of the ML family. It means it abuses of
pattern matching and allows for side effects. As far as I know, lisp and
scheme are pure functionnal langage as they don't allow side effects.
But perhaps I'm wrong. And I'm often wrong. ;)

Standard ml (SML) allows for sideeffects too. Don't know about Lisp/Scheme.

About Ruby, I must tell I find it hard to see where Ruby is functionnal
langage. Coding recursivity in ruby is most of the time so uneasy. I
just wonder, if someone can explain, he'll be welcome.

I have just made a regexp engine where the scanner uses recursion.
Fetch the tar.gz file and look at 'source/scanner_nodes.rb'
http://raa.ruby-lang.org/list.rhtml?name=regexp


For instance the following piece of code are responsible for matching
a charclass. @succ points to the next node in the AST.
@set is an Array, e.g. ['a'..'z', '_', '0'..'9']

See the third line from the bottom, how recursion is working.


class Inside < Base
def initialize(succ, set)
@succ = succ
@set = set
super()
end
attr_reader :succ, :set
def ==(other)
(self.class == other.class) and
(@set == other.set) and
(@succ == other.succ)
end
def check_not_endofinput(context)
return if context.input.has_next?
context.raise_mismatch("(Inside) end of input")
end
def is_member_of_set?(symbol)
@set.each do |i|
return true if i.kind_of?(Range) and i.include?(symbol)
return true if i == symbol
end
false
end
def check_member_of_set(context)
symbol = context.current
return if is_member_of_set?(symbol)
context.raise_mismatch(
"(Inside) symbol #{symbol.inspect} is not in set #{@set.inspect}")
end
def match(context)
#puts "Inside, set=#{@set.inspect}"
check_not_endofinput(context)
check_member_of_set(context)
context.input_next { @succ.match(context) }
end
end
 
D

Dan Doel

Lisp and Scheme can have side effects. Lisp has (setf) and Scheme has
(set!) that allow assignment. Lisp especially, as if I recall correctly, you
can do:

(setf (car a) x)

And it will actually change the value of (car a), so you can change lists
instead of creating new ones (I'm a little rusty, though, so I may be wrong).

Ruby can have a functional 'feel' at times, since a lot of things can be done
by passing around blocks, which are a lot like lambda expressions. However,
Smalltalk has blocks and I doubt anyone would accuse Smalltalk of being
functional. :)

Lack of nice tail recursion would probably limit Ruby from being as efficient
at functional programming as languages designed for it, though.

- Dan
 
L

Lionel Thiry

gabriele renzi a écrit :
il Sat, 01 May 2004 12:52:55 +0200, Lionel Thiry
<[email protected]> ha scritto::





obviously you missed the R language :)
http://www.jbum.com/idt/r.html
I forget to tell about it.
I've read somewhere there are one-caracter-name langages for almost all
letters of the latin alphabet (A -> Z). It seems it still lefts U, I and
T. If someone want to create a one-caracter-name langage, he should
hurry! :)
The original link where I found that is in french, look in the comments:
http://linuxfr.org/2004/04/27/16055.html

Lio
 
K

Kristof Bastiaensen

il Sat, 01 May 2004 12:29:59 +0200, Kristof Bastiaensen


I think this sentence may be incorrect.
I mean, haskell, ocaml and lisp all does not have call/cc yet they're
functional languages.
(actually I'm not sure if lisp, ocaml and scheme can be defined as
functional languages, cause they're not pure ones, if I'm correct)

You are right, I used the term "functional language" in a wrong
way. Ruby isn't functional, because it doesn't encourage a
functional programming style. A meant to say that Ruby treats
functions and continuations as first class objects (just as
in functional languages). You could take a scheme program and
rewrite it in Ruby. It is a pity that the current Ruby-interpreter
doesn't handle tail-recursive call's, I hope that will be in
Ruby 2.0.

Another point where Ruby would come short, is in
scoping rules. Ruby has no equivalent for scheme "let".
Especially with the new local-scoping rules, I have the
impression that it isn't possible to have block local
variables (or am I wrong?). Wouldn't it be useful to have a
local indentifier, to mean the start of a new scope for
these variables:

a = "foo"
4.times do |i|
local a = i * i
end
puts a
=> "foo"

Kristof
 
T

ts

K> a = "foo"
K> 4.times do |i|
K> local a = i * i
K> end
K> puts a
K> => "foo"

Well, in the original message from matz, there are 2 possibilities
* do ||
* let

[ruby-talk:63199]

Now, what do you expect with this (for `a' and `b') ?

1.times do |i|
let a = i
let b = a + 1
end


Guy Decoux
 
K

Kristof Bastiaensen

Well, in the original message from matz, there are 2 possibilities
* do ||
* let

[ruby-talk:63199]

Now, what do you expect with this (for `a' and `b') ?

1.times do |i|
let a = i
let b = a + 1
end


Guy Decoux

Hi,
Both solutions look good to me. The advantage of using do would
be that you could see the scope of the variable more clearly.

Let however would require less typing, because the above would
have been:

1.times do |i|
do |a| a = i
do |b| b = a + 1; end
end
end

But on the other side, block local variables are probably
mostly only useful for closures, so maybe a let keyword is not
necessary.

The local construct may be nice for initializing block local
vars:

local(1, 2) do |i, a|
puts i + i
puts a * a
end
=> 2
=> 4

do without anything before it will then initialize to nil.

Kristof
 
G

Gavin Sinclair

About Ruby, I must tell I find it hard to see where Ruby is functionnal
langage. Coding recursivity in ruby is most of the time so uneasy. I
just wonder, if someone can explain, he'll be welcome.

Ruby has some superficial niceties borrowed from functional languages
(map, filter, etc.) and some deep features inspired by them (lexical
closures), but at the end of the day, it's difficult to say Ruby is
functional when it doesn't have functions :)

Cheers,
Gavin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top