From: Simon Strandgaard Date: 2004-05-01T19:57:53+09:00 Subject: Re: Lazy evaluation (evil) Lionel Thiry wrote: > 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 -- Simon Strandgaard