1. Object to Atom

How can the object {2} be converted to an atom?

Z

new topic     » topic index » view message » categorize

2. Re: Object to Atom

buzzo said...

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 
 
new topic     » goto parent     » topic index » view message » categorize

3. Re: Object to Atom

buzzo said...

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. getlost

-Greg

new topic     » goto parent     » topic index » view message » categorize

4. Re: Object to Atom

BRyan said...
buzzo said...

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: Object to Atom

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) 
 
new topic     » goto parent     » topic index » view message » categorize

6. Re: Object to Atom

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 
new topic     » goto parent     » topic index » view message » categorize

7. Re: Object to Atom

Thanks to all... problem solved..

Z

new topic     » goto parent     » topic index » view message » categorize

8. Re: Object to Atom

evanmars said...
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.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Object to Atom

DerekParnell said...
evanmars said...
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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu