Talk:Rail

From Esolang
Jump to navigation Jump to search

If anyone is interested, the interpreter link (which is dead) can be found on the wayback machine: https://web.archive.org/web/20160324115830/https://user.xmission.com/~tyrecius/rail-0.5.zip I can't work out how to use it though, help appreciated. CrispyPin (talk) 11:29, 15 August 2019 (UTC)


What is a cdr?

"c is a list cell with a == cdr(c) and b == car(c)" --(this comment by Anka at 05:42, 20 Sep 2006 UTC; please sign your comments with ~~~~)

It's a Lisp term; it refers to the entire list apart from its first element. car refers to the first element of the list. Historically, they're acronyms for Content of Decrement Register and Content of Address Register. ais523 07:56, 20 Sep 2006 (UTC)


I have an Ackermann function implementation but I don't know how to format it or anything. Rail is awesome. I had a lot of fun writing it.

[snipped]

--156.34.81.81 21:37, 18 May 2007 (UTC)

Looks perfectly well formatted to me, so I transferred it to the main article. --Ørjan 07:35, 19 May 2007 (UTC)

The description for '*' sounds wrong. shouldn't it allow the train to leave in the same direction? --heretic 04:02, 31 December 2008 (UTC)

Probably, although it sounded slightly ambiguous as it was. I think it is clearer to change a preposition, so I did that. --Ørjan 19:58, 31 December 2008 (UTC)

I have found an error in the interpreter. x-junctions can be passed horizontally and vertically just like the *-junction and +-junctions can be passed diagonally. By the Way: What would you say if the junctions could be used also for direction changes (like x for / and * for /) ? --(this comment by 84.174.99.204 at 09:13, 29 May 2014‎ UTC; please sign your comments with ~~~~)

For loops and playing around

I have had some fun playing with this. I am trying to do a for loop. Is it possible to pass a function on the stack to another function? I'm thinking: passing a, b, fn, to a for-loop function and then doing something like: for( i = a; i <=b; i++){ fn(i) }

Along the lines of:

$'for loop'
 \
  \--(!a!)(!b!)(!fn!)-- etc.

Also: pretty sure your && and || are wrong. I have code for a nicely formatted truth table if you want.

In && where you have: f-{drop} it should be {drop}-f
In || where you have: t-{drop} it should be {drop}-t

Then it should work correctly.

Here are my versions:

$'my &&' (a b -- c)
 \
  \      /--{drop}--f--#
   \----<
         \      /---f--#
          \----<
                \---t--#


$'my ||' (a b -- c)
 \
  \               /---f--#
   \        /----<
    \      /      \---t--#
     \----<
           \--{drop}--t--#

Here is my XOR:

$'my xor' (a b -- c)
 \
  \               /---f--#
   \        /----<
    \      /      \---t--#
     \----<
           \      /---t--#
            \----<
                  \---f--#

I think these nicely show how logic works "under the covers". And the {drop} in 'my &&' and 'my ||' show how lazy evaluation in if statements work. ie, if we {drop} it, then no need to evaluate it. --(this comment by 121.45.148.1 at 18:35, 9 September 2011 UTC; please sign your comments with ~~~~)

List Constructor

How do you create a list? You need an empty list to start with:

  • n creates an empty list on the stack
  • n[item]: creates a list with one element "item"
  • n[item1]:[item2]: creates a list with two elements.

Wrong way: [item1][item2]:

--(this comment by Kinnla at 19:07, 21 April 2014‎ UTC; please sign your comments with ~~~~)

You are right. The 'wrong way' should be disallowed. I tweaked the semantics to make it clear that the list constructor should check whether the thing it is building on is a list. Duerig (talk) 15:27, 21 April 2014 (EDT)

Forth Notation of Type Signatures

For defining the type signature of a rail function the Forth Notation is used.

  • ( -- ) This function does not alter the stack
  • (a -- b) This function pops one element (a) from the stack and pushes one element (b) to the stack.
  • (a b -- c) (b) is on top of the stack and (a) is below. This function pops two elements and pushes one element.

See also: http://wiki.laptop.org/go/Forth_Lesson_2

--(this comment by Kinnla at 19:33, 21 April 2014‎ UTC; please sign your comments with ~~~~)

universal print

This function pops and prints the top stack element. Checking also for "false" lists (created by [a][b]:).

$ 'main' ( -- ): Test universal print
 | 
 |-n1:2:n3::n[]:n4:::5:n:{print}#
 |-n{print}#
 |-n1:{print}#
 \-12:{print}#

$ 'print' (a -- ):
 | Prints any type of data, including nested lists. Checks for chimeras.
 | 
 |                         f-(l)o#
 |                  f-(l)nq<      
  \-(!l!)(l)?[list]q<      t-[<>]o#
                    t-[<]o\      f-(l)~--\
                           -(l)nq<       | 
  /-----------------------/      t-[>]o# |
 /|t                                     |
|  >q[tsil]?(l)(!l!)-o[\]\]{tnirp}o[\[\]-/
| |f           
| \-(l)?[nil]q\ ----[Chimera detected! Starting as a list, but ending as a ]\
|              v     /--------------------------------------------------------@
 \-------------/   @-(l)?[. Please check list constructor.]ppb#

--(this comment by Kinnla at 21:12, 21 April 2014‎ UTC; please sign your comments with ~~~~)

Lambda?

Why is there no description of what & does at all? May it be something about functions as arguments like asked in the question before? --myname 21:46, 21 April 2014‎ (UTC)

& creates a closure, as far as i can see. It works like reflector and pushes the closure to the stack. Closures share the same variables as their parent functions (they are in the same scope). Example usage:
$ 'main' (--):
 \
  \-[hello ](!h!)-[world\n\](!w!)-\
                                  |
   /------------------------------/
   |
   \
  /--&-(w)o-#
  |
  \-(!l!)-(h)o-(l){}#
&-(w)o-# is the closure. As you can see, closure is called using command {}. GermanyBoy (talk) 16:27, 20 May 2014 (UTC)