1. Object to Atom
- Posted by buzzo Jul 02, 2013
- 1403 views
How can the object {2} be converted to an atom?
Z
2. Re: Object to Atom
- Posted by BRyan Jul 02, 2013
- 1382 views
How can the object {2} be converted to an atom?
Z
object my_object my_object = 2 atom my_atom my_atom = 0 -- check the size first if atom(my_object) then ? my_object else puts(1,"Object will not fit in atom\n" ) end if
3. Re: Object to Atom
- Posted by ghaberek (admin) Jul 02, 2013
- 1343 views
How can the object {2} be converted to an atom?
The object {2} is a sequence containing one atom. Do you just want that atom from the sequence?
sequence s = {2} atom a = s[1]
Otherwise I'm not sure what you would do to "convert" it.
-Greg
4. Re: Object to Atom
- Posted by evanmars Jul 02, 2013
- 1371 views
How can the object {2} be converted to an atom?
Z
object my_object my_object = 2 atom my_atom my_atom = 0 -- check the size first if atom(my_object) then ? my_object else puts(1,"Object will not fit in atom\n" ) end if
But the object in OP's post was {2}, not 2. Also you did not show how to convert to an atom, just how to test for it.
5. Re: Object to Atom
- Posted by buzzo Jul 02, 2013
- 1373 views
Thanks... made slight change .. it does not "fit"
object my_object my_object = {2} atom my_atom my_atom = 0 -- check the size first if atom(my_object) then ? my_object else puts(1,"Object will not fit in atom\n" ) end if sleep(5)
6. Re: Object to Atom
- Posted by evanmars Jul 02, 2013
- 1374 views
object s = {2} atom my_atom if sequence(s) then if length(s) = 1 then my_atom = s[1] end if end if ? my_atom
8. Re: Object to Atom
- Posted by DerekParnell (admin) Jul 02, 2013
- 1394 views
object s = {2} atom my_atom if sequence(s) then if length(s) = 1 then my_atom = s[1] end if end if ? my_atom
This is not very robust coding. If 's' is not a sequence or has a length other than 1, then 'my_atom' will not have been assigned anything, so it may crash the program later when you try to use it for anything.
9. Re: Object to Atom
- Posted by evanmars Jul 03, 2013
- 1251 views
object s = {2} atom my_atom if sequence(s) then if length(s) = 1 then my_atom = s[1] end if end if ? my_atom
This is not very robust coding. If 's' is not a sequence or has a length other than 1, then 'my_atom' will not have been assigned anything, so it may crash the program later when you try to use it for anything.
True. I would normally have done something like:
atom my_atom = -1 --or atom my_atom = 0
when declaring it.