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

First example that came to mind for me is in SQL:

  x IS BETWEEN y AND z
A not-quite-binary example would be languages where comparisons chain:

  x < y <= z
    Equivalent to:
  (x < y) && (y <= z)
    (Possibly modulo short-circuiting)
In maths, you would sometimes see clever constructions with reversed relation symbols to succinctly describe many things at once; when written down I would sometimes see relations going out in other directions after left and right were exhausted.

The ‘ternary’ assignment is customisable in OCaml: x.(y) <- z is (maybe was?) exactly equivalent Array.set x y z, including in the parse tree, and so could be can be customised by shadowing the Array module; and custom variants may be defined too, e.g.

  type 'a t = {mutable a : 'a array; mutable p : int }
  
  let push t x =
    ensure_capacity t 1;
    t.a.(t.p) <- x;
    t.p <- t.p + 1

  let (.:()<-) t j x =
    if j >= t.p then raise Out_of_bounds;
    t.a.(j) <- x

  (* one can now use t.:(i) <- x *)
Another weirder mixfix example would be binding operators, but then you accept lots of other syntax too like if then else. Binding operators let you define weird functions with names like (let) or (and) and then:

  let* x = y in z
  (* equivalent to: *)
  (let*) y (fun x -> z)

  let* x1 = y1 and x2 = y2 in z
  (* equivalent to: *)
  (let*) ((and*) y1 y2) (fun (x1, x2) -> z)


yes, in raku that’s spelled

  say my $x=42;  #42


er, what? (⊙_)


oh yeah - that was dumb - sorry I misread the examples in the parent

fwiw I am pointing out that say my $x=42;

is doing the 'my' declaration in the middle of the 'say' and '$x=42' so that providing declarations in the middle of a regular routine such as `say $x` is kind of a ternary syntax in how that stanza is parsed




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

Search: