[27 Apr 2009] Contest anyone? Converting special string into a table

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
User avatar
Clyde
Posts: 348
Joined: Sun Feb 14, 2010 12:38 pm
Location: Dresden / Germany

[27 Apr 2009] Contest anyone? Converting special string into a table

Post by Clyde »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 27 Apr 2009 21:43:38 +0200

Hi list,

maybe you recognized my mail yesterday and Andreas' answer (see below). As I am not a pro, I will need more than 15 minutes. :-) But that is ok. I just thought, whether it wouldn't be a nice thing, if we do a little contest just for fun? Who writes the most efficient/shortest code to parse a special string (see below) into a table? I know, it is no really hard task, but so beginners also have a chance (and fun!!!). Let's say, in one week, all participants send there code here to the list and the we all (or Andreas) elects the winner. The prize is fame and fun. :-) And maybe this source code could help other HW programmers to improve their projects. And the winner is allowed to set a new (more useful/interesting?) task. What do you think? Well, if you find this ridiculous, no problem. :-)

Ah yes, and I think of this string which should be a nice Hollywood table in the end:

Code: Select all

string$ = {x = 100, y = 50, {10, 11, {12, {13}, z = 30}, [6] = 16, 14},
15, obj = "Cube"}
If you have better suggestions, let me/us know.

So: happy coding! :-)

Greetings Micha
Currently using: Hollywood 9 with Windows IDE and Hollywood 9 with Visual Studio Code and hw4vsc
User avatar
Allanon
Posts: 732
Joined: Sun Feb 14, 2010 7:53 pm
Location: Italy
Contact:

[30 Apr 2009] Re: Contest anyone? Converting special string into a table

Post by Allanon »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Thu, 30 Apr 2009 08:07:07 -0000

I think I've solved the puzzle :) This code need more optimization and actually stores all the items as strings so you have to find a way to detect if a number is a number or a string for example:

{ x = 100 }

the index <x> is stored as a string and <100> is also storeed as a string, maybe you want to add code to convert the string 100 into a number. You may define a rule to store string making mandatory to add the quotes and then detect them and do not convert the item into a number...

Anyway you should have a good starting point with my function, hoping that it works in all cases because I've not had the time to test deeply

Good coding, Fabio
Locked