Questions about List2Code and Passing Functions through Eval

41 views
Skip to first unread message

Anthony Souls

unread,
Aug 22, 2023, 3:30:17 PM8/22/23
to The Ring Programming Language

List2code.png

My questions are in the snapshot, but I will reiterate them:

Why doesn't List2Code display a string for objects? Are objects encoded as bytes or something?

Secondly, is there any way to programmatically retrieve the object.func name to store as a string, then eval later, like "Obj2String" or something similar? 

I am going through the sample code to learn more of the language, and those are the two questions I had. Thx. 

Mahmoud Fayed

unread,
Aug 25, 2023, 3:06:29 PM8/25/23
to The Ring Programming Language
Hello Anthony

>> "Why doesn't List2Code display a string for objects? Are objects encoded as bytes or something?"

The List2Code is just a simple function written in Ring itself


The function is designed to process lists that could have strings, numbers & nested lists
Objects are not part of the List2Code() design

If you need this feature, You can implement it
The function isObject() and Attributes() could be useful


Greetings,
Mahmoud

Azzeddine Remmal

unread,
Aug 25, 2023, 4:06:04 PM8/25/23
to The Ring Programming Language
Hello   Anthony

I had modified an existing list2code() in tocode() and added attributes to the object
I hope it helps you
And you can add functions of the object
Greetings


#--------------------------------------------------------------

#for printing

#--------------------------------------------------------------

func ToCode(aInput)

cCode = "["

lStart = True

for item in aInput

if !lStart cCode += ","+Char(32) else lStart = False ok

if isString(item)

item2 = item

item2 = substr(item2,'"','"+char(34)+"')

cCode += Char(32) +'"' + item2 + '"'

but isnumber(item)

cCode += Char(32) +""+item

but islist(item)

cCode += Windowsnl()

cCode += ToCode(item)

but isobject(item)

aAttribut = attributes(item)

cCode += '['

lStart = True

for attribut in aAttribut

if !lStart cCode += "," else lStart = False ok

value = getattribute(item,attribut)

cCode +=':'+ attribut + '='

if isString(value)

cCode += '"' + value + '"'

but isNumber(value)

cCode += value

but isList(value)

cCode += ToCode(value)

but isobject(value)

cCode += ToCode(value)

ok

next

cCode += " ]" +Windowsnl()

ok

next

cCode += Char(32)+"]"


return cCode





Tocode.png

ToCode.ring

Azzeddine Remmal

unread,
Aug 25, 2023, 4:36:30 PM8/25/23
to The Ring Programming Language
testToCode.png

Anthony Souls

unread,
Aug 25, 2023, 9:11:59 PM8/25/23
to Azzeddine Remmal, The Ring Programming Language
Thanks, I will experiment with that later on. I am taking a break from the Ring Programming for a while. 

I was trying to modify Ring Notepad to have code folding, then realized it didn't support css style "display:none", which really foiled my idea, lol. 
Now, the only way to do it might be overly hackish, so I'm worn out :) 

It looks cool. Appreciate your time and energy into making it. I will check it out and see what I can do with it. I just thought that List2code should print out objects. I thought maybe it was stored in some format that prevented it, but I guess not. Like, get the object as code, then change the object through string manipulations, then translate it back into an object. I thought that would be a cool toy experiment, but yeah :) 

Thx

--

---
You received this message because you are subscribed to a topic in the Google Groups "The Ring Programming Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ring-lang/i49djQwL4GU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/545dd49f-d488-4615-b96d-5180d228f9a3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages