views:

350

answers:

2

I recently stumbled over a very odd source listing on a rather old programming-related site (lost it somewhere in my browser history as I didn't care about it at first).

I think that this is part of a simple (console-based?) snake game.

I searched and searched but didn't find a language that looked similar. It seems like a mix of Python, Ruby, and C++.

What programming language is this?

my Snake.hasProps
 {
   length
   parts
   xDir
   yDir
 } & hasMethods {
   init: length = 0
         parts[0].x,y = 5

   move: parts[ 0 ].x,y.!add xDir | yDir             # Move the head
         map parts(i,v): parts[ i ] = parts[ i + 1 ]
         checkBiteSelf
         checkFeed

   checkBiteSelf: part

 }

my SnakePart.hasProps
 {
   x
   y
 }

fork SnakePart to !Feed

my Game.hasProps
 {
   frameTime = 30
 } & hasMethods {
   init: mainloop
   mainloop: sys.util.sleep frameTime

             Snake.move
             Field.getInput -> Snake.xDir | Snake.yDir
             Field.reDraw with Snake
                               & Feed
                               & Game # For FPS

 }

main.isMethod
 {
   game.init
 }
+4  A: 

I don't know which language it is, but here is what I would guess about the syntax/keywords:

  • Objects/classes are defined using the my keyword
  • the .hasProps { ... } construct is used to add properties to an object
  • & hasMethods { ... } is used to add methods to an object.
    • Methods are defined using name: ...
    • Initially I thought that indentation was part of the syntax, but the Field.reDraw with Snake ... does not follow the same format so whitespace is probably not important.
    • The use of & instead of chaining .hasMethods { ... } is very interesting...
  • sys.util.sleep is the only library reference I can see, and I can't find any language that uses that name for a sleep function.
  • main.isMethod appears to be the way you declare the starting method, which in this case calls the game.init method.
  • snake.parts appears to be an array of the SnakePart object defined with x and y properties:
    • parts[0].x,y = 5 probably sets the x and y coordinates for part[0] to 5. I haven't ever seen this type of syntax before, so again this is probably a custom language for a CS compiler class or a DSL.
    • Err... just saw fork SnakePart to !Feed... maybe Snake.part is different than SnakePart...
  • # is used to start a comment (Same as Perl, Python, and many other languages)
  • init: length = 0 is an initial variable assignment for Snake.length (similar to how python does property assignments).
  • An object's properties are referenced using only their name, where as another objects properties are referenced using the object.name (ie game.init)
  • Methods are called using object.method arguments such as sys.util.sleep frameTime

Things that I am not sure about:

  • What is the ! operator used for?
    • parts[ 0 ].x,y.!add xDir | yDir ???
    • fork SnakePart to !Feed ???
  • What does map parts(i,v): parts[ i ] = parts[ i + 1 ] do? Looks like a Map function with a lambda expression where i is the input and v is the output.
  • What does Field.getInput -> Snake.xDir | Snake.yDir do?
    • Where is Field defined?
    • What is the -> operator?
    • What is the purpose for Field.reDraw with Snake & Feed & Game ???
  • There appears to be some missing methods or libraries:
    • checkfeed is not defined, unless it is a reference to the !Feed
    • checkBiteSelf: part: part is not defined anywhere unless it refers to SnakePart
    • Field is used but not defined.

Did I miss anything? :-P

Greg Bray
+2  A: 

This is a small fragment of logo#

kruiser
You mean this LoGo#? http://web.archive.org/web/20060524151817/http://sourceforge.net/projects/logosharp/ I can't find any code samples of that... but there is another version called SharpLogo: http://sourceforge.net/projects/sharplogo/files/
Greg Bray