Erlang/OTP Forums

Author Message

<  Erlang  ~  Late night question on records and types...

seancharles
Posted: Tue Aug 07, 2007 10:09 pm Reply with quote
User Joined: 18 Jul 2007 Posts: 57
Given the record:
Code:
-record( menuitem,
    {
      label,      % Printable string label
      id,         % numerical identifier
      page,      % the /pages/<page>.yaws display page
      title=null      % Browser title string, null = default
    }).


and a population of:
Code:

    #menuitem { label="Home",
       id=1,
       page=home},


How do I get the 'id' to be a number, currently my lookup code fails because it has a number and an atom ?

What did I do wrong ?
Sad
View user's profile Send private message
Jan Henry Nystrom
Posted: Wed Aug 08, 2007 2:23 am Reply with quote
User Joined: 09 Oct 2006 Posts: 28 Location: Uppsala, Sweden
seancharles wrote:
Given the record:
Code:
-record( menuitem,
    {
      label,      % Printable string label
      id,         % numerical identifier
      page,      % the /pages/<page>.yaws display page
      title=null      % Browser title string, null = default
    }).


and a population of:
Code:

    #menuitem { label="Home",
       id=1,
       page=home},


How do I get the 'id' to be a number, currently my lookup code fails because it has a number and an atom ?

What did I do wrong ?
Sad


I am not entirely sure what the question is, so I will state what I think it is and then answer that question. Are you asking how to get the position of the id field in the tuple representing the record? In that case you can write #menuitem.id which will evaluate to 3. If you are trying to lookup a member in a list for example, one would write
Code:
 listst:keysearch(4711, #menuitem.id, List)

to retrieve the record with id 4711 from a list of menuitem records.

/Cheers Henry

_________________
Jan Henry Nystrom
Training & Research Manager @ Erlang Training and Consulting Ltd
http://www.erlang-consulting.com
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger ICQ Number
Mazen
Posted: Wed Aug 08, 2007 8:27 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Quote:
currently my lookup code fails because it has a number and an atom


Not quite sure what you mean here... care to elaborate for us? Smile
View user's profile Send private message
seancharles
Posted: Fri Aug 10, 2007 11:07 am Reply with quote
User Joined: 18 Jul 2007 Posts: 57
Sorry about the delay, been offline for a few days.

Anyway, I have read all your comments and learnt a few tricks so far!

Read my lips: N - O - O - B - I - E

That's me! 42 this year and still a newbie! Never too old to be a newbie eh! LOL The mistake, again, was mine, god I love/hate Erlang. HA HA HA... in a nutshell, I was was actually calling list_to_atom() in a higher up call and didn't see it for the trees!

I am writing a commercial web application as a personal project. Erlang has so many advantages that I can't begin to count them! I think in a few months time I will be ready to host, test and then launch my service, I think it will be a pretty unique thing when its finished, if only my lameness at reading the documentation would stop holding me up.

Pattern matching for example, every time I read the docs I learn something new, the best examples I have so far are YAWS source code (I'm using it to run my service after reading a yaws/apache shoot-out) and it blows me away.

Pattern matching rocks, then there are guard expressions and case statements. Man, I didn't think it could get Better than Smalltalk, then I read Alan Kays' quote about LISP, then I thought LISP was the dogs and after struggling with SBCL and getting to like it I got a bit pissed at not having a 'stable and portable' (no flame war intended) environment that had *everything in it* out of the box.

Erlang has that.

Better stop here, I could talk all day about how much Erlang has my interest.

Thanks for all your help guys,
Sean Charles.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum