#{eval code}" Regards robert [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Robert [ip] => bob.news@gmx.ne [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 4 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> #{eval code}" >[/ref] Thanks Robert, I understand what you mean: it looks like code, but it's a String. Smart, but I was looking for real code. Thanks anyway. Ciao, Giuliano -- If you want to send me an email in the address you have to write 'p', then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Piergiuliano [ip] => p_bossi_AGAINST [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 7 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> 1+2==3 ==>true [ref] > >[/ref] [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => <402AA13D.9060709@ps.ge.com> [ref] => <4027DB92.3000201@ps.ge.com> [htmlstate] => on_nl2br [postusername] => Bermejo, [ip] => rodrigo.bermejo [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 9 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> > 1+2==3 ==>true[/ref] Neat! But it is still working on strings, doesn't it? Thanks, Giuliano -- If you want to send me an email in the address you have to write 'p', then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <4027DB92.3000201@ps.ge.com> <402AA13D.9060709@ps.ge.com> [htmlstate] => on_nl2br [postusername] => Piergiuliano [ip] => p_bossi_AGAINST [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 10 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> > > 1+2==3 ==>true[/ref] > > Neat! > > But it is still working on strings, doesn't it?[/ref] Yes, it does. It's basically the same as eval < 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => <4027DB92.3000201@ps.ge.com> <402AA13D.9060709@ps.ge.com> [htmlstate] => on_nl2br [postusername] => Robert [ip] => bob.news@gmx.ne [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 11 [islastshown] => 1 [isfirstshown] => [attachments] => [allattachments] => ) --> evaluate and print an expression - Ruby

evaluate and print an expression - Ruby

I hope that what I'm asking doesn't sound too weird, but I'm trying to understand if in ruby is possible to print and evaluate an expression at the same time. I know for example that I can do like this: irb(main):001:0> expr = "1+2==3" => "1+2==3" irb(main):002:0> puts expr + ' ==> ' + (eval expr).to_s 1+2==3 ==> true => nil What I don't like is to specify the expression as a string. I'd rather prefer to manage code directly, but I don't know exactly how to print it and evaluate it at the same time. Ideally, I'd like to ...

  1. #1

    Default evaluate and print an expression

    I hope that what I'm asking doesn't sound too weird, but I'm trying to
    understand if in ruby is possible to print and evaluate an expression at
    the same time. I know for example that I can do like this:

    irb(main):001:0> expr = "1+2==3"
    => "1+2==3"
    irb(main):002:0> puts expr + ' ==> ' + (eval expr).to_s
    1+2==3 ==> true
    => nil

    What I don't like is to specify the expression as a string. I'd rather
    prefer to manage code directly, but I don't know exactly how to print it
    and evaluate it at the same time. Ideally, I'd like to change the
    following code in order to print block body:

    irb(main):012:0> def evaluate(&code)
    irb(main):013:1> p code
    irb(main):014:1> code.call
    irb(main):015:1> end
    => nil
    irb(main):016:0> evaluate { 1+2==3 }
    #<Proc:0x02a4ea78(irb):16>
    => true

    Do you see what I mean? Instead of having:
    #<Proc:0x02a4ea78(irb):16>
    I'd like to get:
    { 1+2==3 }
    or something like that.

    I know that in lisp this can be easily done due to its nature (that is,
    code is data and data is code), but in ruby?

    Thanks for your help!
    Ciao, Giuliano

    --
    If you want to send me an email in the address you have to write 'p',
    then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last

    Piergiuliano Guest

  2. #2

    Default Re: evaluate and print an expression



    def evaluate(code)
    puts "#{code}==>"
    eval code
    end

    evaluate("1+2==3")

    1+2==3 ==>
    true




    Piergiuliano Bossi wrote:
     




    Bermejo, Guest

  3. #3

    Default Re: evaluate and print an expression

    Bermejo, Rodrigo wrote: 

    :-)

    Ok, I understand that I haven't explained myself clearly.

    The point is not how to make it work with an expression as a String
    ("1+2==3" for example), but working directly with code.

    At the end the question is: is it possible to print the code of an
    expression?

    Remember that I'm trying to do something like this:

    irb(main):012:0> def evaluate(&code)
    irb(main):013:1> p code
    irb(main):014:1> code.call
    irb(main):015:1> end
    => nil
    irb(main):016:0> evaluate { 1+2==3 }
    #<Proc:0x02a4ea78(irb):16>
    => true

    Instead of having:
    #<Proc:0x02a4ea78(irb):16>
    I'd like to get:
    { 1+2==3 }
    or something like that.

    I think that the answer in ruby is: no, it's not possible.
    But I may be wrong.

    Ciao, Giuliano


    --
    If you want to send me an email in the address you have to write 'p',
    then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last

    Piergiuliano Guest

  4. #4

    Default Re: evaluate and print an expression


    "Piergiuliano Bossi" <it> schrieb im
    Newsbeitrag news:c08kj7$hnm$tiscalinet.it... 

    You can't without manually parsing the source file. The closest you might
    get without extra parsing might be this, but still "code" is a String:

    code=<<CODE
    1 + 2 == 3
    CODE
    puts "#{code} --> #{eval code}"

    Regards

    robert

    Robert Guest

  5. #5

    Default Re: evaluate and print an expression

    Piergiuliano Bossi <it> wrote 

    Nope, you can't. I've read a rationale for this somewhere, but I don't
    remember the details.
    jesse Guest

  6. #6

    Default Re: evaluate and print an expression

    jesse rudolph wrote: 
    >
    >
    > Nope, you can't. I've read a rationale for this somewhere, but I don't
    > remember the details.[/ref]

    :-)

    Ok, this is what I thought.

    Thanks, Giuliano

    --
    If you want to send me an email in the address you have to write 'p',
    then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last

    Piergiuliano Guest

  7. #7

    Default Re: evaluate and print an expression

    Robert Klemme wrote:
     
    >
    >
    > You can't without manually parsing the source file. The closest you might
    > get without extra parsing might be this, but still "code" is a String:
    >
    > code=<<CODE
    > 1 + 2 == 3
    > CODE
    > puts "#{code} --> #{eval code}"
    >[/ref]

    Thanks Robert, I understand what you mean: it looks like code, but it's
    a String.

    Smart, but I was looking for real code.

    Thanks anyway.
    Ciao, Giuliano

    --
    If you want to send me an email in the address you have to write 'p',
    then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last

    Piergiuliano Guest

  8. #8

    Default How to create babel-17


    http://www.rubyist.net/~matz/slides/oscon2003/mgp00001.html


    Julio Guest

  9. #9

    Default Re: evaluate and print an expression



    Piergiuliano Bossi wrote:
     

    take a look at irb/xmp - print exemple.

    <-------------
    require 'irb/xmp'

    xmp <<END
    1+2==3
    END
    ------------->
    1+2==3
    ==>true

     




    Bermejo, Guest

  10. #10

    Default Re: evaluate and print an expression

    Bermejo, Rodrigo wrote: 
    >
    >
    > take a look at irb/xmp - print exemple.
    >
    > <-------------
    > require 'irb/xmp'
    >
    > xmp <<END
    > 1+2==3
    > END
    > ------------->
    > 1+2==3 ==>true[/ref]

    Neat!

    But it is still working on strings, doesn't it?

    Thanks, Giuliano

    --
    If you want to send me an email in the address you have to write 'p',
    then a dot, followed by 'bossi' at 'quinary', another dot and 'com' at last

    Piergiuliano Guest

  11. #11

    Default Re: evaluate and print an expression


    "Piergiuliano Bossi" <it> schrieb im
    Newsbeitrag news:c0g6qb$hba$tiscalinet.it... 
    > >
    > >
    > > take a look at irb/xmp - print exemple.
    > >
    > > <-------------
    > > require 'irb/xmp'
    > >
    > > xmp <<END
    > > 1+2==3
    > > END
    > > ------------->
    > > 1+2==3 ==>true[/ref]
    >
    > Neat!
    >
    > But it is still working on strings, doesn't it?[/ref]

    Yes, it does. It's basically the same as

    eval <<END
    1+2==3
    END

    Regards

    robert

    Robert Guest

Similar Threads

  1. Evaluate my site...
    By WickedSense in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: January 13th, 11:06 PM
  2. Avoiding Evaluate
    By perezle in forum Macromedia ColdFusion
    Replies: 4
    Last Post: June 14th, 11:21 AM
  3. #26262 [Opn->Bgs]: Error in evaluate logical expression
    By iliaa@php.net in forum PHP Development
    Replies: 0
    Last Post: November 15th, 05:56 PM
  4. #26262 [NEW]: Error in evaluate logical expression
    By updates at mail dot ru in forum PHP Development
    Replies: 0
    Last Post: November 15th, 02:35 PM
  5. Replies: 2
    Last Post: August 24th, 02:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •