Live data from Hacker News

Factor: A Practical Stack Language

factorcode.org

41–46 of 46 posts

Re: Factor: A Practical Stack Language

#41

Ha! I implemented "concatenative" programming for Java as Binding [1] (or Unit) expressions, but had no idea. Seriously, never came across that term before this post. The idea with binding expressions is the type of expression A and the type of expression B implement "reactions" with one another in order to form a binding expression when they are lexically adjacent. 65 mph The type of `mph` defines a post reaction me…

If you see units as multiplicative factors: 1.5 USD = 1.5 * USD 65 mph = 65 * mile / hour you can then use simple algebra to solve unit conversion and many other common deductive reasoning questions ("how many miles per gallon...?"), relying on the units to guide you to the solution. There's probably a name for this, and it is indeed built into the SI notation (km/h vs mph).

Sounds like https://en.wikipedia.org/wiki/Dimensional_analysis

Re: Factor: A Practical Stack Language

#42

In case anyone else was curious, Slava Pestov is now at Apple working on Swift. Top of his twitter[1] is a WWDC22 talk "Design protocol interfaces in Swift"[2] (but video seems 1x-only - I don't see a copy on yt - there's a transcript). [1] https://twitter.com/slava_pestov [2] https://developer.apple.com/videos/play/wwdc2022/110353/

He is also the person behind the JEdit editor (or at least one of the main guys).

Re: Factor: A Practical Stack Language

#43
post #15
post #2

Be careful. Factor is a gateway to lower level stack based languages. I saw Zed Shaw do a presentation using factor and decided to spend a weekend playing with it. It was the start of a two year journey that ended with me writing forth for microcontrollers. That was time I should have studied but was somehow always sidelined by other things.

Hah, you could have done worse. The double-dose introduction to stack-based programming via HP calculators and Adobe PostScript in the 90s led me to spend on the order of 3000 hours developing Onyx ( https://github.com/canonware/onyx ), which started off as a PostScript clone minus graphics, and ended up a thing of its own. On the bright side, I learned a tremendous amount about lexing, interpreters, exceptions, tail…

Fun stuff! I find that the more I find out about PL research and what I myself like in programming, the more I feel constrained in many languages.

I find that most of the bugs I write (which are many) are errors in dealing with mutable state. There is always one stupid little detail that leads to bad state. This has led me to dislike the programming language I write the most (probably python, despite really only wanting to write scheme) because it is mutation first. I was also sad to discover that I couldn't write self-recursive procedures in rust because they are never guaranteed to be actually recursive.

Did you get anything like that from your work with onyx? (And yes, I believe I have actually has a look at onyx about 10 years ago, back when trying to write poatscript).

Re: Factor: A Practical Stack Language

#44
post #26

Earlier quoted context omitted.

From the FAQ [0]: > How is Factor different from Forth? > Forth is untyped, not garbage collected, and close to the machine. For flow control, Forth code tends to use immediate words. Variables and arrays tend to be global, and programs aren't usually written in a functional manner. Factor is very different from this. It is dynamically typed, offering a high degree of reflection. Unreferenced objects are garbage coll…

Does anyone know of a Forth-like language that would be similarly low level, but allowing for nested word definitions for more HOF-centric approach?

I'm developing one at https://git.sr.ht/~remexre/rtf -- it's nowhere near ready for general use, but idiomatic code looks like:

    : parse-digit ( u -- u -1 | 0 0 )
      { DUP $30 $3a WITHIN } { $30 - TRUE }
      { DUP $41 $5b WITHIN } { $37 - TRUE }
      { DUP $61 $7b WITHIN } { $57 - TRUE }
      { ." parse-digit 1: " TODO } 3 CASE ;
    : add-digit ( u u -- u flag )
      ." add-digit 0: " TODO
      ;
    : parse-digits-0 ( u addr len -- u flag )
      { OVER B@ -ROT { parse-digit } 2DIP ROT
        { { SWAP base B@ * + } 2DIP 1 /STRING parse-digits-0 } WHEN
      } { DROP TRUE } ?COND ;
    : parse-digits ( u addr len -- u flag )
      { parse-digits-0 } { DROP FALSE } ?COND ;
    : parse-prefix-if-exists ( addr len -- addr len 0|1|2 )
      DUP {
        OVER B@
        { DUP $2d = } { DROP 1 /STRING 1 }
        { DUP $7e = } { DROP 1 /STRING 2 }
        { DROP 0 } 2 CASE
      } { 0 } COND ;
    : parse-base-if-exists ( addr len -- addr len base )
      DUP {
        OVER B@
        { DUP $23 = } { DROP 1 /STRING #10 }
        { DUP $24 = } { DROP 1 /STRING $10 }
        { DUP $25 = } { DROP 1 /STRING %10 }
        { DUP $5e = } { DROP 1 /STRING ^10 }
        { DROP 2DUP $3a SCAN DUP } {
          1 /STRING { NIP - 1- 10 BASE B! 0 -ROT parse-digits } 2KEEP
          ROT { ROT } {
            ." parse-base-if-exists 1: " TODO
          } COND
          \ ." parse-base-if-exists 2: " TODO
        }
        { 2DROP base B@ } 5 CASE
      } { base B@ } COND ;
    : with-saved-base ( x*i { x*i -- x*j } -- x*j )
      base B@ SWAP DIP base B! ;
    : apply-prefix ( u 0|1|2 -- n )
      { } { NEGATE } { INVERT } 3 SWITCH ;
    : parse-number ( addr len -- u -1 | 0 0 )
      { parse-base-if-exists base B! parse-prefix-if-exists
        { 0 -ROT parse-digits } DIP
        SWAP { apply-prefix TRUE } { DROP FALSE } COND
      } with-saved-base ;
(This being an incomplete rewrite of the bootstrapped text interpreter's number parser; as I said, nowhere near ready.)

Re: Factor: A Practical Stack Language

#45

Ha! I implemented "concatenative" programming for Java as Binding [1] (or Unit) expressions, but had no idea. Seriously, never came across that term before this post. The idea with binding expressions is the type of expression A and the type of expression B implement "reactions" with one another in order to form a binding expression when they are lexically adjacent. 65 mph The type of `mph` defines a post reaction me…

If you see units as multiplicative factors: 1.5 USD = 1.5 * USD 65 mph = 65 * mile / hour you can then use simple algebra to solve unit conversion and many other common deductive reasoning questions ("how many miles per gallon...?"), relying on the units to guide you to the solution. There's probably a name for this, and it is indeed built into the SI notation (km/h vs mph).

This is already implemented with manifold's unit expressions, but is made richer and more readable via concatenative features. For instance, '1.5 * USD' is not as readable as simply '1.5 USD'. However, unit expressions leverage operators for dimensional arithmetic:

Force f = 5 kg * 9.807 m/s/s; // result: 49.035 Newtons

Area space = (20ft + 2in) * (37ft + 7.5in); // result: 758 37/48 ft²

All unit expressions internally store amounts as SI units, which enables interunit expressions.

Length height = 6 ft + 4 cm; // mix SI and US units

out.println(height.to(ft)); // display any unit

You aren't limited to units. Generally, any concatenative sequence can be implemented. Like ranges:

IntegerRange range = 1 to 5;

Here the `to` identifier's type implements reactions to Number types to produce range types, which enables:

for (int i: 1 to 5) { out.println(i); }

See the manifold project's Unit and Science modules:

Units: https://github.com/manifold-systems/manifold/tree/master/man...

Science: https://github.com/manifold-systems/manifold/tree/master/man...

Re: Factor: A Practical Stack Language

#46
post #31
post #29

Earlier quoted context omitted.

There shouldn't be any captchas. Do you mean on the website, like Cloudflare captchas? Which country/vpn/whatever are coming from?

On the website, like a Google captcha. I clicked through to see what the macro story was like and was hit with a captcha. USA, no VPN.

Just took a look on desktop. I'm just inadvertently being sent to edit links with empty content when looking at some of the language features, and edits are recaptcha protected.
Post reply on HN