1. 11

If someone tries this, could you tell me if the C file compiles and runs (precompiled/flpc-gen.f takes the least amount of time to finish)? I haven’t tested it on anything but my own machine and don’t know C very well. Thanks!

  1.  

  2. 2

    It’s been running for a couple of minutes now, but I guess it’s working.

    Very interesting language!

    Edit: Took ~15 minutes to get to a REPL?!

    1. 2

      Thanks for trying this out and reporting back! Which file in precompiled/ did you pass it?

      If you just want its (FlpcForth) REPL, then ./flpc with no arguments should work. Nothing is defined in that case, of course. You can try to paste in some source from precompiled/*.

      The sample sources in precompiled/ are all for parsing (some of) its own source and/or generating its own source. That’s why it takes so long (although even that shouldn’t…).

      There’s no FlpcPython REPL yet (it can parse FlpcPython but doesn’t know what to do with the resulting AST). So right now, to write FlpcPython, I suggest writing to a file, say foo.flpc, and running

      python compiler.py lib/stage{0,1{a,c,d},3{a,b}}.flpc foo.flpc > foo.f
      ./flpc foo.f
      

      This uses the external Python compiler which will eventually be removed.

      1. 1

        Thanks. I ran precompiled/flpc-all.f. Oh, I just noticed that you recommended flpc-gen.f above :/

    2. 1

      Interesting project, but I have a question regarding:

      Python is Lisp with syntactic sugar and Lisp is Forth with syntactic sugar.

      Could you elaborate further on this point? I’m guessing it’s not to be taken literally, but although I have heard of the connections between Python and Lisp (map, fliter, lambda, …) I haven’t heard about the second connection. Wasn’t FORTH invented in the 1970’s and LISP in the 1950’s? I’m guessing the order of appearance isn’t strictly necessary, but you don’t often hear about newer programming languages making older ones more “difficult”.

      1. 3

        I’m guessing it’s not to be taken literally, but although I have heard of the connections between Python and Lisp (map, fliter, lambda, …) I haven’t heard about the second connection. Wasn’t FORTH invented in the 1970’s and LISP in the 1950’s?

        I think the idea is that Lisp is a delimited, prefix language (e.g. (foo (bar baz) quux)) while Forth is an undelimited, postfix language (e.g. quux @ baz @ bar foo, where baz & quux are words which put an address on the stack, bar is a word which pops a value from the stack and pushes a value on the stack & foo is a word which pops two values from the stack and does something).

        You can imagine that one could work up to a Lisp from something like OPAREN quux OPAREN baz bar CPAREN foo CPAREN in Forth, where OPAREN & CPAREN are special Forth words which do the obvious thing.

        1. 3

          Its nothing so profound. Just a remark about syntax. Its almost as bargap explained. To go from Lisp to Forth

          (foo (bar baz) quux)
          

          Put the function at the end of the list instead of the beginning so (func arg1 arg2 arg3) becomes (arg1 arg2 arg3 func).

          ((baz bar) quux foo) 
          

          And remove the parenthesis

          baz bar quux foo
          

          This should produce the same output when run in Forth. (Assuming constants are functions with no parameters and return the constant. And adjust for autoquoting and implicit returns.)

          The same goes for the Python to Lisp transfomration. Replace all syntax with calls to their dunder equivalent, put the functions inside the parenthesis and remove the comma separators (func(arg1, arg2, arg3) becomes (func args1 arg2 arg3)) and turn indented blocks into quotes (and put them as the last argument of the block heading).

          1. 2

            I still don’t see the link they’re trying to make with lisp and forth, especially considering their lisp example looks and seems nothing like lisp…

            consider their example

            bind("fib" fun([i]
                           [if(<(i 3) [return(1)])
                            return(+(fib(-(i 1)) fib(-(i 2))))]))
            

            against common lisp

            (defun fib (i)
             (if (< i 3)
              1
              (+ (fib (- i 1)) (fib (- i 2)))))
            
            1. 2

              To do the reverse transformation:

              (defun fib (i)
                (if (< i 3)
                 1
                 (+ (fib (- i 1)) (fib (- i 2)))))
              

              Put function names in front of the parenthesis.

              defun(fib (i)
               if(<(i 3)
                  1
                  +(fib(-(i 1)) fib(-(i 2)))))
              

              Add explicit returns.

              defun(fib (i)
               if(<(i 3)
                  return(1)
                  return(+(fib(-(i 1)) fib(-(i 2))))))
              

              Put square bracket for quotes to distinguish them from calls.

              defun(fib [i]
                if(<(i 3) return(1)
                   return(+(fib(-(i 1)) fib(-(i 2))))))
              

              Change which arguments need to be quoted and which ones don’t.

              defun("fib" [i]
                [if(<(i 3) [return(1)]
                    return(+(fib(-(i 1)) fib(-(i 2))))]))
              

              (Some of these transformations I’ve seen on discussions on possibilities for Lisp syntax.)