POV-Ray : Newsgroups : povray.off-topic : Logic programming : Re: Some code Server Time
1 Oct 2024 15:23:50 EDT (-0400)
  Re: Some code  
From: Darren New
Date: 2 Apr 2008 10:54:04
Message: <47f3ac1c$1@news.povray.org>
Invisible wrote:
> Please, be my guest... I've never seen any non-trivial Erlang sources.

OK. Right now I'm working on a Jotto game. That's been my "second 
program" since high school on languages where I needed to figure out how 
they work.  (First being "hello world" of course.)

I'm happy to post that when I finish too.

I'm also trying to figure out in the back of my head how to translate a 
bunch of the SQL stuff at work to use Mnesia, which is Erlang's database 
system.  (Apparently, the name was originally "Amnesia" until one of the 
managers pointed out what a bad idea it was to name a database system 
"Amnesia." :-)

> [Would you also like to see the parser and pretty printer? They're not 
> much larger. ;-) ]

Sure. Erlang has such built in (for Erlang literals, at least), but 
sure. :-)

Incidentally, any reason you can see why this with 5600 lines of input 
would take 10 seconds and with 100,000 lines of input (20 times as big) 
it would take more than an hour?  Am I doing something stupidly N^2 or 
is it the memory management doing something odd?


load_file_words(IO, Acc) ->
     % Read one space-delimited string from the IO chan with no prompt
     Read = io:fread(IO, [], "~s"),
     case Read of
         {ok, [[]]} -> load_file_words(IO, Acc); % blank line
         {ok, [Word]} -> load_file_words(IO, [Word|Acc]); % found word
         eof -> Acc; % End of file, return accumulated answers
         {error, What} -> erlang:error(What) % crash out
     end.

Isn't this how you're supposed to do the functional programming loop bit? :)

-- 
   Darren New / San Diego, CA, USA (PST)
     "That's pretty. Where's that?"
          "It's the Age of Channelwood."
     "We should go there on vacation some time."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.