lout-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pushing the limits [useless]


From: Samuel Lacas
Subject: Pushing the limits [useless]
Date: Wed, 31 Oct 2001 09:37:58 +0100

Hi,

I was recently re-reading the Lout documentation, and the following
sentence (2.3 in Design document) made me smile:

   A programming language may be considered complete when it attains the
   power of a Turing machine, but no such criterion seems relevant to
   document formatting.

And indeed, Lout does not seem to provide a lot of computational
features (@Next, although @Plus and @Minus are reserved keywords).
However, you have recursion, unary integers with @Next, and pairs and
projectors (@Case), which means that Lout language is actually Turing
complete (though not efficient, of course), at least theoretically.

To convince myself, I wrote a function which computes the roman
representation of an arabic integer (less than 5000, because I do not
know the symbols for greater values); one can now use roman numerals
in Lout up to 4999 ;)  Of course, the algorithm has a (little bit more
than) linear computation time in the size of the integer you convert,
which makes it quite useless in practice; but I found it quite funny
to write :)

Does anyone on the list have ever wrote similar useless functions ?

WARNING: this message, whereas Lout oriented, is a little bit out of 
subject, I feel. If anyone finds thinks it rubbish or considers it
annoying, please excuse me (and let me know so I won't post Lout
horrible definitions again). Thank you.

sL
----
# Converting a numeral to a Roman numeral

# Converts a single digit, depending on its rank,
# which is one of "Unit", "Ten", "Hundred", "Thousand"
def @ADigitToRDigit
   named which { Unit }
   named @Upper { No }
   right x
{
   def ator
      left y
      named one { ? }
      named five { ? }
      named nine { ? }
   {
      {y} @Case {
        {1} @Yield { one }
        {2} @Yield {{one}{one}}
        {3} @Yield {{one}{one}{one}}
        {4} @Yield {{one}{five}}
        {5} @Yield {{five}}
        {6} @Yield {{five}{one}}
        {7} @Yield {{five}{one}{one}}
        {8} @Yield {{five}{one}{one}{one}}
        {9} @Yield {nine}
# Needed for leading zeros
         else @Yield { }
      }
   } # ator

   @Upper @Case {
      {No} @Yield {
         {which} @Case {
            {Unit} @Yield { x ator one{"i"} five{"v"} nine{"ix"} }
            {Ten}  @Yield { x ator one{"x"} five{"l"} nine{"xc"} }
            {Hundred} @Yield { x ator one{"c"} five{"d"} nine{"cm"} }
            {Thousand} @Yield { x ator one{"m"} five{"?"} nine{"?"} }
            else @Yield ?
         } # which
      }
      else @Yield {
         {which} @Case {
           {Unit} @Yield { x ator one{I} five{V} nine{IX} }
           {Ten}  @Yield { x ator one{X} five{L} nine{XC} }
           {Hundred} @Yield { x ator one{C} five{D} nine{CM} }
           {Thousand} @Yield { x ator one{M} five{?} nine{?} }
            else @Yield ?
         } # which
      } #else
   } #Upper
} # @ADigitToRDigit

def @ToRomanNum
   named @Upper { No }
   right @ArabNum
{
   
# The big one. It counts up to the found arab number, updating the digits one
# by one.
# If one of the digits is 10, simply overflow onto the next,
# otherwise, check if found, otherwise step to the next counter
   def @Count
      left counter
      named thos {0}
      named huns {0}
      named tens {0}
      named ones {1}
   {
       {ones} @Case {
          {10} @Yield {
             counter @Count
             thos { thos }
             huns { huns }
             tens { @Next tens }
             ones { 0 }
          }
          else @Yield {
          tens @Case {
             {10} @Yield {
                counter @Count
                thos { thos }
                huns { @Next huns }
                tens { 0 }
                ones { ones }
             }
          else @Yield {
          huns @Case {
             {10} @Yield {
                counter @Count
                thos { @Next thos }
                huns { 0 }
                tens { tens }
                ones { ones }
             }
          else @Yield {
          thos @Case {
             { 5 6 7 8 9 10 } @Yield {
                ?Too big for the Romans?
             }
          else @Yield {
            counter @Case {
               address@hidden @Yield {# At least !
                  0c @Space {
                     address@hidden @address@hidden which{Thousand} thos}
                     address@hidden @address@hidden which{Hundred}  huns}
                     address@hidden @address@hidden which{Ten}      tens}
                     address@hidden @address@hidden                 ones}
                  }
               } # @ArabNum found
               else @Yield {
                  address@hidden counter} @Count
                  thos { thos }
                  huns { huns }
                  tens { tens }
                  ones { @Next ones }
               } # increment counter 
            }
          }
          } # check if found
          } # thos overflow check
          } # huns overflow check
          } # tens overflow check
          } # ones overflow check
          }
       }
   } # @Count
#launch the infernal machine
   1 @Count #thos{0} huns{0} tens{0} ones{1}
}
----


reply via email to

[Prev in Thread] Current Thread [Next in Thread]