Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Experiment - Quine

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jan 19th, 2014, 5:28am    Post subject: Experiment - Quine Reply with quote

I was looking at Rosetta Code today and happened upon the Quine task, which inspired me to try to write one in ViviFire. I decided to use some features that I've considered but haven't yet implemented in the parser. If you all find this syntax agreeable, I'll probably add support in the next EXE release.
Code:
Dim a$()={"Dim a$()={","#null a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL"}
#null a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL

The features include:
  • Implicit dimensioning and initialization of arrays by using a list of elements inside curly braces
  • String constants by ASCII code/Unicode offset by preceding a number with a dollar sign, including all number bases (e.g. $42, $H2A, $O52, $B101010).
  • Similarly, string constants by (abbreviated) name, such as the $NL above which represents the platform-dependent newline character/sequence.

Semantically, the above code implies that the #Null object has a default method that sends a string to some output buffer such as stderr or a debugger's output window. I'm also considering naming this #Debug instead.

What do you think?

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
nukesrus21
Junior Member


Joined: 19 Oct 2010
Posts: 13
Location: Southbury, CT

PostPosted: Jan 20th, 2014, 4:44pm    Post subject: Re: Experiment - Quine Reply with quote

Brent,

These would all be great features!!

I would definitely change the #Null to #Debug though as I always think of the null character when I see something like #Null. #Debug would help to ensure that the user knows whatever comes afterward will be sent to an output of some kind. I assume you'll automatically detect if a (the) debugger is open and send it to that; otherwise I think you may need another variable to tell the language where the output is to be sent.

Just my thoughts on it....

{:0)

Brandon
Back to top
View user's profile Send private message
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Jan 20th, 2014, 6:37pm    Post subject: Re: Experiment - Quine Reply with quote

I think that #null should be reserved to represent nothing or uninitialized.

#debug would be simple and understandable as triggering debug output.

_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jan 20th, 2014, 11:52pm    Post subject: Re: Experiment - Quine Reply with quote

Thanks for the comments. I just added support for the mentioned constructs. But then I discovered that my example has a syntax error.

The second line begins #null a$(0), which is parsed as a normal method call rather than the expected anonymous method call. After this, the parser expects a line break, but finds a + instead, causing the "oh so helpful" error -- line 2 col 12: this symbol not expected in Newline. I probably should do something about that.

The correct code follows.
Code:
Dim a$()={"Dim a$()={","#debug (a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL)"}
#debug (a$(0)+$34+a$(0)+$34+$44+$34+a$(1)+$34+$125+$NL+a$(1)+$NL)

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Jan 21st, 2014, 8:49am    Post subject: Re: Experiment - Quine Reply with quote

What I still see as strange is the missing closing curly brace in the first line of code.
If this is the supported syntax, it is fully on the contrary to what one is used from other languages utilizing curly braces.

_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jan 21st, 2014, 4:52pm    Post subject: Re: Experiment - Quine Reply with quote

Stefan, the closing curly brace is represented by $125 which translates into LB as Chr$(125). The second line cannot contain any quotes, otherwise they'd need to be escaped in the first line. This makes the code simpler.
_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group