This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: ease of making DSLs in Scala - nobody cares

5 replies
loverdos
Joined: 2008-11-18,
User offline. Last seen 2 years 27 weeks ago.
[Reply to All] was the intention, I believe...

On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech <vaclav.pech@seznam.cz> wrote:
That looks impressive! Would you mind sharing the definition of your DSL?

Vaclav



   But on the last two slides I showed how to implement this:

   object Playground extends BasicClass {
     def main(args: Array[String]) {        10 PRINT "SCALA ROCKS!"
       20 GOTO 10

       RUN
     }
   }

   And everybody got interested!

   Maybe next time I will start with showing inline BASIC... ;-)

   Szymon

   --    ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ




Szymon Jachim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: ease of making DSLs in Scala - nobody cares
The slides (at least the natural language part) are in Polish, but since you asked:    http://docs.google.com/Presentation?docid=ajgz5ch8kfv9_26kxsbw8f6
Hope you weren't hoping for more than PRINT/GOTO ;-) and more Scalish code. The reason it is what it is is that I came up with the idea in the night bus home after 12 hours shift and implemented it next day during launch break. My first program did exactly that: "PRINT something/GOTO previous line" and that's what I wanted to get running on top of Scala. Fifteen years after the original was written... :-)
class BasicClass {
  abstract sealed class BasicLine 
  case class PrintLine(num: Int, s: String) extends BasicLine
  case class GotoLine(num: Int, to: Int) extends BasicLine
  val lines = new scala.collection.mutable.HashMap[Int, BasicLine]
  case class linebuilder(num: Int) {
    def GOTO(to: Int) = lines(num) = GotoLine(num, to)
    def PRINT(s: String) = lines(num) = PrintLine(num, s)
  }
  private def gotoLine(line: Int) {
    lines(line) match {
      case PrintLine(_, s) => println(s); gotoLine(line + 10)
      case GotoLine(_, to) => gotoLine(to)
    }
  }
  def RUN {
    gotoLine(lines.keys.toList.first)
  }
  implicit def int2linebuilder(i: Int) = linebuilder(i)
}

I can image getting a Turing complete subset of BASIC, if you choose to prepend every variable with apostrophe ('):    10 FOR 'I = 1 TO 10     20 PRINT "SCALA ROCKS!"   30 NEXT 'I
Szymon  
On Wed, Mar 11, 2009 at 11:20 AM, Christos KK Loverdos <loverdos@gmail.com> wrote:
[Reply to All] was the intention, I believe...

On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech <vaclav.pech@seznam.cz> wrote:
That looks impressive! Would you mind sharing the definition of your DSL?

Vaclav



   But on the last two slides I showed how to implement this:

   object Playground extends BasicClass {
     def main(args: Array[String]) {        10 PRINT "SCALA ROCKS!"
       20 GOTO 10

       RUN
     }
   }

   And everybody got interested!

   Maybe next time I will start with showing inline BASIC... ;-)

   Szymon

   --    ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ




venca
Joined: 2009-03-11,
User offline. Last seen 2 years 27 weeks ago.
Re: ease of making DSLs in Scala - nobody cares

Hi Szymon,

thank you for sharing. This is a very nice mental exercise, indeed.

Vaclav

Szymon Jachim wrote:
> The slides (at least the natural language part) are in Polish, but
> since you asked:
> http://docs.google.com/Presentation?docid=ajgz5ch8kfv9_26kxsbw8f6
>
> Hope you weren't hoping for more than PRINT/GOTO ;-) and more Scalish
> code. The reason it is what it is is that I came up with the idea in
> the night bus home after 12 hours shift and implemented it next day
> during launch break. My first program did exactly that: "PRINT
> something/GOTO previous line" and that's what I wanted to get running
> on top of Scala.
> Fifteen years after the original was written... :-)
>
> class BasicClass {
> abstract sealed class BasicLine
> case class PrintLine(num: Int, s: String) extends BasicLine
> case class GotoLine(num: Int, to: Int) extends BasicLine
> val lines = new scala.collection.mutable.HashMap[Int, BasicLine]
> case class linebuilder(num: Int) {
> def GOTO(to: Int) = lines(num) = GotoLine(num, to)
> def PRINT(s: String) = lines(num) = PrintLine(num, s)
> }
> private def gotoLine(line: Int) {
> lines(line) match {
> case PrintLine(_, s) => println(s); gotoLine(line + 10)
> case GotoLine(_, to) => gotoLine(to)
> }
> }
> def RUN {
> gotoLine(lines.keys.toList.first)
> }
> implicit def int2linebuilder(i: Int) = linebuilder(i)
> }
>
> I can image getting a Turing complete subset of BASIC, if you choose
> to prepend every variable with apostrophe ('):
>
> 10 FOR 'I = 1 TO 10
> 20 PRINT "SCALA ROCKS!"
> 30 NEXT 'I
>
> Szymon
>
> On Wed, Mar 11, 2009 at 11:20 AM, Christos KK Loverdos
> > wrote:
>
> [Reply to All] was the intention, I believe...
>
> On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech
> > wrote:
>
> That looks impressive! Would you mind sharing the definition
> of your DSL?
>
> Vaclav
>
>
>
>
> But on the last two slides I showed how to implement this:
>
> object Playground extends BasicClass {
> def main(args: Array[String]) { 10 PRINT
> "SCALA ROCKS!"
> 20 GOTO 10
>
> RUN
> }
> }
>
> And everybody got interested!
>
> Maybe next time I will start with showing inline
> BASIC... ;-)
>
> Szymon
>
> -- ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>
>
>
>
> --
> __~O
> -\ <, Christos KK Loverdos
> (*)/ (*) http://ckkloverdos.com
>
>
>
>
>
> --
> __~O
> -\ <, Christos KK Loverdos
> (*)/ (*) http://ckkloverdos.com
>
>
>
>

Szymon Jachim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: ease of making DSLs in Scala - nobody cares

    case class TOexpr(a: Int, a2: Int) 

    implicit def any2TOexr(a: Int) = new {

      def TO(a2: Int) = TOexpr(a, a2)

    } 

    object X {

      object FOR {

        def update(s: Symbol, to: TOexpr) = {

          println(s, to)                  

        } 

      }

    } 


If somebody want to extend this example to have for loops he may want to take a look at it. :-)
Szymon
On Wed, Mar 11, 2009 at 11:48 AM, Szymon Jachim <sjachim@gmail.com> wrote:
The slides (at least the natural language part) are in Polish, but since you asked:    http://docs.google.com/Presentation?docid=ajgz5ch8kfv9_26kxsbw8f6
Hope you weren't hoping for more than PRINT/GOTO ;-) and more Scalish code. The reason it is what it is is that I came up with the idea in the night bus home after 12 hours shift and implemented it next day during launch break. My first program did exactly that: "PRINT something/GOTO previous line" and that's what I wanted to get running on top of Scala. Fifteen years after the original was written... :-)
class BasicClass {
  abstract sealed class BasicLine 
  case class PrintLine(num: Int, s: String) extends BasicLine
  case class GotoLine(num: Int, to: Int) extends BasicLine
  val lines = new scala.collection.mutable.HashMap[Int, BasicLine]
  case class linebuilder(num: Int) {
    def GOTO(to: Int) = lines(num) = GotoLine(num, to)
    def PRINT(s: String) = lines(num) = PrintLine(num, s)
  }
  private def gotoLine(line: Int) {
    lines(line) match {
      case PrintLine(_, s) => println(s); gotoLine(line + 10)
      case GotoLine(_, to) => gotoLine(to)
    }
  }
  def RUN {
    gotoLine(lines.keys.toList.first)
  }
  implicit def int2linebuilder(i: Int) = linebuilder(i)
}

I can image getting a Turing complete subset of BASIC, if you choose to prepend every variable with apostrophe ('):    10 FOR 'I = 1 TO 10     20 PRINT "SCALA ROCKS!"   30 NEXT 'I
Szymon  
On Wed, Mar 11, 2009 at 11:20 AM, Christos KK Loverdos <loverdos@gmail.com> wrote:
[Reply to All] was the intention, I believe...

On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech <vaclav.pech@seznam.cz> wrote:
That looks impressive! Would you mind sharing the definition of your DSL?

Vaclav



   But on the last two slides I showed how to implement this:

   object Playground extends BasicClass {
     def main(args: Array[String]) {        10 PRINT "SCALA ROCKS!"
       20 GOTO 10

       RUN
     }
   }

   And everybody got interested!

   Maybe next time I will start with showing inline BASIC... ;-)

   Szymon

   --    ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ




Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: ease of making DSLs in Scala - nobody cares

You might find this Haskell DSL interesting:
http://augustss.blogspot.com/2009/02/more-basic-not-that-anybody-should-...

2009/3/11 Szymon Jachim :
>     case class TOexpr(a: Int, a2: Int)
>
>     implicit def any2TOexr(a: Int) = new {
>
>       def TO(a2: Int) = TOexpr(a, a2)
>
>     }
>
>     object X {
>
>       object FOR {
>
>         def update(s: Symbol, to: TOexpr) = {
>
>           println(s, to)
>
>         }
>
>       }
>
>     }
>
> If somebody want to extend this example to have for loops he may want to
> take a look at it. :-)
> Szymon
> On Wed, Mar 11, 2009 at 11:48 AM, Szymon Jachim wrote:
>>
>> The slides (at least the natural language part) are in Polish, but since
>> you asked:
>>   http://docs.google.com/Presentation?docid=ajgz5ch8kfv9_26kxsbw8f6
>> Hope you weren't hoping for more than PRINT/GOTO ;-) and more Scalish
>> code. The reason it is what it is is that I came up with the idea in the
>> night bus home after 12 hours shift and implemented it next day during
>> launch break. My first program did exactly that: "PRINT something/GOTO
>> previous line" and that's what I wanted to get running on top of Scala.
>> Fifteen years after the original was written... :-)
>> class BasicClass {
>>   abstract sealed class BasicLine
>>   case class PrintLine(num: Int, s: String) extends BasicLine
>>   case class GotoLine(num: Int, to: Int) extends BasicLine
>>   val lines = new scala.collection.mutable.HashMap[Int, BasicLine]
>>   case class linebuilder(num: Int) {
>>     def GOTO(to: Int) = lines(num) = GotoLine(num, to)
>>     def PRINT(s: String) = lines(num) = PrintLine(num, s)
>>   }
>>   private def gotoLine(line: Int) {
>>     lines(line) match {
>>       case PrintLine(_, s) => println(s); gotoLine(line + 10)
>>       case GotoLine(_, to) => gotoLine(to)
>>     }
>>   }
>>   def RUN {
>>     gotoLine(lines.keys.toList.first)
>>   }
>>   implicit def int2linebuilder(i: Int) = linebuilder(i)
>> }
>>
>> I can image getting a Turing complete subset of BASIC, if you choose to
>> prepend every variable with apostrophe ('):
>>
>>   10 FOR 'I = 1 TO 10
>>   20 PRINT "SCALA ROCKS!"
>>   30 NEXT 'I
>> Szymon
>> On Wed, Mar 11, 2009 at 11:20 AM, Christos KK Loverdos
>> wrote:
>>>
>>> [Reply to All] was the intention, I believe...
>>>
>>> On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech
>>> wrote:
>>>>
>>>> That looks impressive! Would you mind sharing the definition of your
>>>> DSL?
>>>>
>>>> Vaclav
>>>>
>>>>
>>>>
>>>>>    But on the last two slides I showed how to implement this:
>>>>>
>>>>>    object Playground extends BasicClass {
>>>>>      def main(args: Array[String]) {        10 PRINT "SCALA ROCKS!"
>>>>>        20 GOTO 10
>>>>>
>>>>>        RUN
>>>>>      }
>>>>>    }
>>>>>
>>>>>    And everybody got interested!
>>>>>
>>>>>    Maybe next time I will start with showing inline BASIC... ;-)
>>>>>
>>>>>    Szymon
>>>>>
>>>>>    --    ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  __~O
>>>>> -\ <,       Christos KK Loverdos
>>>>> (*)/ (*)      http://ckkloverdos.com
>>>>
>>>
>>>
>>>
>>> --
>>>  __~O
>>> -\ <,       Christos KK Loverdos
>>> (*)/ (*)      http://ckkloverdos.com
>>
>>
>>
>> --
>> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>
>
>
> --
> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>

Szymon Jachim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: ease of making DSLs in Scala - nobody cares
Oh gosh... I DO NOT BELIEVE IN TELEPATHY.But sometimes it's so hard to resist...
Szymon

On Wed, Mar 11, 2009 at 5:34 PM, Ricky Clarkson <ricky.clarkson@gmail.com> wrote:
You might find this Haskell DSL interesting:
http://augustss.blogspot.com/2009/02/more-basic-not-that-anybody-should-care.html

2009/3/11 Szymon Jachim <sjachim@gmail.com>:
>     case class TOexpr(a: Int, a2: Int)
>
>     implicit def any2TOexr(a: Int) = new {
>
>       def TO(a2: Int) = TOexpr(a, a2)
>
>     }
>
>     object X {
>
>       object FOR {
>
>         def update(s: Symbol, to: TOexpr) = {
>
>           println(s, to)
>
>         }
>
>       }
>
>     }
>
> If somebody want to extend this example to have for loops he may want to
> take a look at it. :-)
> Szymon
> On Wed, Mar 11, 2009 at 11:48 AM, Szymon Jachim <sjachim@gmail.com> wrote:
>>
>> The slides (at least the natural language part) are in Polish, but since
>> you asked:
>>   http://docs.google.com/Presentation?docid=ajgz5ch8kfv9_26kxsbw8f6
>> Hope you weren't hoping for more than PRINT/GOTO ;-) and more Scalish
>> code. The reason it is what it is is that I came up with the idea in the
>> night bus home after 12 hours shift and implemented it next day during
>> launch break. My first program did exactly that: "PRINT something/GOTO
>> previous line" and that's what I wanted to get running on top of Scala.
>> Fifteen years after the original was written... :-)
>> class BasicClass {
>>   abstract sealed class BasicLine
>>   case class PrintLine(num: Int, s: String) extends BasicLine
>>   case class GotoLine(num: Int, to: Int) extends BasicLine
>>   val lines = new scala.collection.mutable.HashMap[Int, BasicLine]
>>   case class linebuilder(num: Int) {
>>     def GOTO(to: Int) = lines(num) = GotoLine(num, to)
>>     def PRINT(s: String) = lines(num) = PrintLine(num, s)
>>   }
>>   private def gotoLine(line: Int) {
>>     lines(line) match {
>>       case PrintLine(_, s) => println(s); gotoLine(line + 10)
>>       case GotoLine(_, to) => gotoLine(to)
>>     }
>>   }
>>   def RUN {
>>     gotoLine(lines.keys.toList.first)
>>   }
>>   implicit def int2linebuilder(i: Int) = linebuilder(i)
>> }
>>
>> I can image getting a Turing complete subset of BASIC, if you choose to
>> prepend every variable with apostrophe ('):
>>
>>   10 FOR 'I = 1 TO 10
>>   20 PRINT "SCALA ROCKS!"
>>   30 NEXT 'I
>> Szymon
>> On Wed, Mar 11, 2009 at 11:20 AM, Christos KK Loverdos
>> <loverdos@gmail.com> wrote:
>>>
>>> [Reply to All] was the intention, I believe...
>>>
>>> On Wed, Mar 11, 2009 at 12:03 PM, Vaclav Pech <vaclav.pech@seznam.cz>
>>> wrote:
>>>>
>>>> That looks impressive! Would you mind sharing the definition of your
>>>> DSL?
>>>>
>>>> Vaclav
>>>>
>>>>
>>>>
>>>>>    But on the last two slides I showed how to implement this:
>>>>>
>>>>>    object Playground extends BasicClass {
>>>>>      def main(args: Array[String]) {        10 PRINT "SCALA ROCKS!"
>>>>>        20 GOTO 10
>>>>>
>>>>>        RUN
>>>>>      }
>>>>>    }
>>>>>
>>>>>    And everybody got interested!
>>>>>
>>>>>    Maybe next time I will start with showing inline BASIC... ;-)
>>>>>
>>>>>    Szymon
>>>>>
>>>>>    --    ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>  __~O
>>>>> -\ <,       Christos KK Loverdos
>>>>> (*)/ (*)      http://ckkloverdos.com
>>>>
>>>
>>>
>>>
>>> --
>>>  __~O
>>> -\ <,       Christos KK Loverdos
>>> (*)/ (*)      http://ckkloverdos.com
>>
>>
>>
>> --
>> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>
>
>
> --
> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>



--
ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland