Live data from Hacker News

Array Languages: R vs. APL (2023)

jcarroll.com.au

11–20 of 68 posts

Re: Array Languages: R vs. APL (2023)

#11
post #5

One of the wildest R features I know of comes as a result of lazy argument evaluation combined with the ability to programmatically modify the set of variable bindings. This means that functions can define local variables that are usable by their arguments (i.e. `f(x+1)` can use a value of `x` that is provided from within `f` when evaluating `x+1`). This is used extensively in practice in the dplyr, ggplot, and other…

Asking out of lack of experience with R: how does such invocation handle case when `x` is defined with a different value at call site?

In pseudocode:

  f =
  let x = 1 in # inner vars for f go here
  arg -> arg + 1 # function logic goes here

  # example one: no external value
  f (x+1) # produces 3 (arg := (x+1) = 2; return arg +1)

  # example two: x is defined in the outer scope
  let x = 4 in
  f (x+2) # produces 5 (arg := 4; return arg + 1)? Or 3 if inner x wins as in example one?

Re: Array Languages: R vs. APL (2023)

#13

> "So, would APL be “readable” if I was more familiar with it? Let’s find out!" An alternative test for this hypothesis might have been using the language J, which is an array language based on APL and by the designer of APL but only using ASCII characters.

R itself could be considered a test of this hypothesis, too. It’s been said that elegant, powerful Lisp would be more widely adopted if it wasn’t for all those gosh-darned parenthesis. Well, at its core R is a Lisp (specifically, Scheme) but with a more traditional syntax (infixed operators, function calls, etc). And it’s fair to say the adoption of R has, indeed, been more widespread than that of Lisp.

J it's standalone, it doesn't use APL in the background.

Re: Array Languages: R vs. APL (2023)

#14
post #2

I personally think APL is wonderful simply because of the original APL specific keyboard [1] I've looked briefly at R and found the syntax and semantics to be less than stellar. Obviously there's going to be some bias in that sentiment due me not generally doing "array programming", but I don't believe the things that irked me were entirely as a result of that. The more annoying stuff for R is entirely second hand. A…

R has a lot high quality packages which implement e.g. frequently used sophisticated regression analysis algorithms. Python has these too but in my experience they are not that well tested and suffer from bugs.

Re: Array Languages: R vs. APL (2023)

#15
post #5

One of the wildest R features I know of comes as a result of lazy argument evaluation combined with the ability to programmatically modify the set of variable bindings. This means that functions can define local variables that are usable by their arguments (i.e. `f(x+1)` can use a value of `x` that is provided from within `f` when evaluating `x+1`). This is used extensively in practice in the dplyr, ggplot, and other…

For those who haven't run into anything about this corner of R before:

https://blog.moertel.com/posts/2006-01-20-wondrous-oddities-...

Re: Array Languages: R vs. APL (2023)

#16
>> find the GCD (greatest common divisor) of the smallest and largest numbers in an array

Just for a short comparison, In J the analogous code is /

  Where / is for reduce, +. is for the GCD,  the LCM is *. 

 The basic idea of J notation is using some small change to mean the contrary, for example {. for first and {: for last, {. for take and }. for drop (one symbol can be used as a unary or binary operator with different meaning.  So if floor is 
The matrix m, the sum of the rows, and the maximum of the sum of the rows in J (separated by ;)

  m ; (+/ m) ; >./ +/ m
  ┌─────┬───────┬──┐
  │0 1 2│9 12 15│15│
  │3 4 5│       │  │
  │6 7 8│       │  │
  └─────┴───────┴──┘

Re: Array Languages: R vs. APL (2023)

#17
Not an array language (AFAIU), but here are some of the mentioned problems solved in (glorious) Factor:

    : find-gcd ( nums -- gcd )
      [ infimum ] [ supremum ] bi gcd nip ;

    : max-wealth ( accounts -- n )
      [ sum ] map-supremum ;

    : which-max-wealth ( accounts -- i )
      [ sum ] supremum-by* drop ;

    primes-upto

Re: Array Languages: R vs. APL (2023)

#18

> "So, would APL be “readable” if I was more familiar with it? Let’s find out!" An alternative test for this hypothesis might have been using the language J, which is an array language based on APL and by the designer of APL but only using ASCII characters.

R itself could be considered a test of this hypothesis, too. It’s been said that elegant, powerful Lisp would be more widely adopted if it wasn’t for all those gosh-darned parenthesis. Well, at its core R is a Lisp (specifically, Scheme) but with a more traditional syntax (infixed operators, function calls, etc). And it’s fair to say the adoption of R has, indeed, been more widespread than that of Lisp.

I'm not sure I would come to this conclusion. R has some adoption, but it's also really not used as a generic programming language, which most Lisp dialects are.

Re: Array Languages: R vs. APL (2023)

#19
post #5

One of the wildest R features I know of comes as a result of lazy argument evaluation combined with the ability to programmatically modify the set of variable bindings. This means that functions can define local variables that are usable by their arguments (i.e. `f(x+1)` can use a value of `x` that is provided from within `f` when evaluating `x+1`). This is used extensively in practice in the dplyr, ggplot, and other…

Asking out of lack of experience with R: how does such invocation handle case when `x` is defined with a different value at call site? In pseudocode: f = let x = 1 in # inner vars for f go here arg -> arg + 1 # function logic goes here # example one: no external value f (x+1) # produces 3 (arg := (x+1) = 2; return arg +1) # example two: x is defined in the outer scope let x = 4 in f (x+2) # produces 5 (arg := 4; retu…

Well the point is that the function can define its own logic to determine the behaviour. Users can also (with some limits) restrict the variable scope.

Re: Array Languages: R vs. APL (2023)

#20
> what if we just generate all products from the set of numbers 2:n and exclude those as "not prime" from all the numbers up to n?

It's fun to translate terse APL to somewhat terse numpy. The result still can be very compact and you can parse it easily if you're used to looking at numpy:

    s = arange(2, 50); p = outer(s, s).ravel(); sorted(set(s) - set(p))
Post reply on HN