Giter VIP home page Giter VIP logo

flobnar's Issues

Rewrite evaluator in continuation-passing style and add I/O

This should permit us to add I/O while only making a handful of functions monadic. (Basically the "trampoline" would be monadic and would do I/O on behalf of the continuations it executes.) This seems marginally cleaner than making the entire evaluator monadic. But experiment and see.

Add "order of evaluation" rules to the README

The README states without explanation that

|    0
|  5 p  <
|    0  +@
|    g  <
|    0
= Result: 5

and also that

8
*,<  5
9 +@>*
  >,*7
    3

is supposed to print Hi, not iH. In both examples, it seems like the north branch is getting evaluated "before" the south branch, but I don't know if that's meant to be a general rule. (Maybe the right-hand branch is always evaluated before the left-hand branch!)

A more "functional-spirited" rule would be that each branch spawns a completely new copy of funge-space, so that side-effects happening in one branch can never be observed by the other branch, and thus the interpreter could memoize and/or multi-thread any way it wanted. However, this rule clearly conflicts with existing examples such as the p/g one above.

If we are indeed guaranteed that the north operand is always evaluated before the south operand, then we can write a "non-explicitly recursive" factorial program like this:

|  0  0
| >g >p:
| *  /0#  <<<  \@
| >    v       6
| #0201
|  g` |<
|  0>g
|  #00
|  -p<
|  10+<
| ^  <
= Result: 720

Notice the application of / as a short-circuiting conditional operator: "evaluate to the north, then, if the condition to the south is true, return the result of the north evaluation; else return the result of evaluating to the east." Here the condition to the south is always 0, so I'm just using / as a more compact version of + that evaluates north-then-east instead of north-then-south.

What happens when "the other side" of a cell is also its "north" or "south" side?

Maybe these rules are intentional, but without explicit calling-out in the README, it feels like they might have been oversights (of the kind that reduce fun more than increase it).

The p term evaluates to the north to get an x coordinate, then to the south to get a y coordinate. It then evaluates what is on the other side of it to get a value.

Does this imply that

|   v<
|   #+@
|   1#
|   p1
|   6g
|    6
= Result: 6

because the 6 south of the p is evaluated twice โ€” once as the y coordinate and then again as the "what is on the other side of" the p?

Similarly:

The \ term takes what to the south of it evaluates to, and uses that as the argument as it "applies" the "one-argument" "function" on the other side of it.

|   v\@
|   \2
|   >*
|    :
= Result: 8

because the second slash first evaluates "to the south" (2*:) to get the value 4, and then uses 4 as the argument to the function "on the other side of it" (identically 2*:) to get 2*4=8.

I'm generally surprised by the fixed cardinal directions in Flobnar, btw. It would feel much more "Befungey" if you had made

|  1+2
|   ^@
= Hypothetical Result: 3

(whereas with the fixed north/south rule, my understanding is that this program should produce infinite-recursion-and-crash while trying to evaluate the north operand of +).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.