Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wonder if the results would be better with a less idiomatic assignment syntax, like perhaps a throwback from the 60s:

    LET A = 10
    LET B = 20
    LET A = B
or a page out of TI's book:

    10 → A
    20 → B
    B → A
or perhaps something reminiscent of several of Apple's older natural-language programming experiments:

    put 10 into a
    put 20 into b
    put b into a
(The languages I'm referencing here are, respectively, classic BASIC, TI BASIC, and Applescript/Hypertalk.)


Several older languages—including Pascal and the Algol languages—will use the := operator for all assignment, on the grounds that assignment is a fundamentally asymmetric operation. In the ML family of languages, there are immutable definitions and mutable reference cells, and different operators for each:

    (* multiple bindings, so the inner x shadows the
     * outer x---indeed, this code would give you a
     * warning about the unused outer x *)
    let x = 5 in
      let x = 6 in x
    (* y is a mutable reference cell being modified *)
    let y = ref 5 in
      y := 6; y
Haskell makes a distinction between name-binding and name-binding-with-possible-side-effect, but still reserves = to mean signify an immutable definition and not assignment:

    -- this defines x to be one more than itself---which
    -- causes an infinite loop of additions when x is used
    let x = x + 1 in x
    -- a different assignment operator is used in a context
    -- in which side-effects might occur, and can be
    -- interspersed with non-side-effectful bindings:
    do { x <- readInt -- does IO
       ; let y = 1    -- doesn't do IO
       ; return (x + y)
       }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: