robpike / ivy

ivy, an APL-like calculator
Other
1.31k stars 102 forks source link

Need an Ivy discussion forum to ask user questions - e.g. where Alpha and Omega commands? #28

Open benjamin-rood opened 8 years ago

benjamin-rood commented 8 years ago

Hi Rob, sorry to bother you here, but I don't see how in Ivy you can use the APL α and ω commands, e.g. if I wanted to create a gcd operator like so:

screen shot 2016-06-17 at 3 08 20 pm

src: http://dfns.dyalog.com/n_gcd.htm

robpike commented 8 years ago

You can't, at least not yet. Ivy is far from a complete mapping of APL's features, even APL\360. I believe the more powerful versions α and ω came much later, perhaps in APL2. I'm not sure.

Of course you can always define a unary or binary operator and name the arguments yourself; there are examples in the ivy help text. But looping and conditionals are not available.

I may do something about that one day but have no plans to do so.

benjamin-rood commented 8 years ago

Thanks for the response. I wonder how one could do a recursive gcd operator then without conditionals? Ultimately I wanted to try to implement a binary coprime operator where op x coprime n produces a vector with all natural numbers ≤ n which are coprime to x.

I do appreciate that as you say, this is a plaything. I very much enjoyed the implementation in Go presentation and I learnt a lot from it, so thank you.

rsc commented 2 years ago

I noticed this is still open, presumably because of the 'need an Ivy discussion forum' part since the conditional execution now exists. One possibility would be to enable GitHub Discussions on this repo. We've used them for Go discussions that are expected to be too much for the issue tracker, and the single level of threading is really helpful.

We tend to only use them for big things in Go, but projects often use them now for Q&A etc. https://github.com/golang/go/discussions/47141 is one of our smaller discussions.

robpike commented 2 years ago

Could do that. It hasn't really had enough users to be worth doing until you started posting all these power-user videos :)

fumin commented 2 years ago

Could we not panic in value.Errorf? In particular, value.index already does bounds checking, so repanicking seems wierd.

By the way, sincere gratitude for creating this wonderful piece of software!!

A bit of background why I prefer not panicking I actually want to use ivy as a script language embedded in a Go programme. The Go programme is doing image manipulation on [Gerber](https://en.wikipedia.org/wiki/Gerber_format) images. In particular, it is trying to match parts of an image to a golden image. Due to the fragmentation of the PCB industry, there are myriad ways how our suppliers describe their manufactured parts. I can't handle all these different ways, so I am thinking of letting operators figure out the image mapping with their own eyeballs, and script it out to the programme. You may ask why not simply let operators input three numbers denoting the X, Y translations and theta for rotation. This is because in order to increase mechanical efficiency, some parts may contain multiple heads and work on many units simulatenously. In other words, the image mapping is something like: ``` op panel p = p[0] > 0 && p[1] > 0: p[0]*cos(theta) + p[1]*sin(theta) p[0] < 0 && p[1] > 0: ... ... ``` I was initially thinking of using https://github.com/pkujhd/goloader to allow operators to write in Go, but hacking Go's linker seems to fragile. Then I thought of `GOARCH=wasm`, but moving slices in and out of wasm is a pain in the ass. Moreover, `GOARCH=wasm` in it's current state is not much faster than an interpreter. In the end, I found ivy, which seems suited for these kinds of mathematical tasks. However, if ivy's `value.Errorf` panics, I would need to `recover` which feels like I am commiting a sin.
fumin commented 2 years ago

Why does (5 5 rho iota 25)[3 2; 1 2 3] return the following?

11 12
13  6
 7  8

I was expecting

11 12 13 
6 7  8

which is also what's returned by https://tryapl.org/ with the expression (5 5 ⍴ ⍳ 25)[3 2; 1 2 3].

Below is my investigation ``` (5 5 rho iota 25)[3 2; 1] 11 6 (5 5 rho iota 25)[3 2; 1 2] 11 12 6 7 (5 5 rho iota 25)[3 2; 1 2 3] 11 12 13 6 7 8 ```
robpike commented 2 years ago

value.Errorf panics because that is how the interpreter does error recovery. it's an easy way to do exception handling. Otherwise the control flow from deep in the interpreter during a calculation would require threading errors through a vast collection of code.

It's common for language implementations and related systems to work like this.

robpike commented 2 years ago

Regarding the indexing example, that's the usual APL way, as you can see by trying the example on https://tryapl.org/. The vector left of the semicolon selects the first axis, while the vector on the right selects the second.

fumin commented 2 years ago

@robpike thanks for your explanation and for sharing your experience in language and systems implementation. I have few experience in language and systems implementation, so it's enlightening to learn that panic and recover can be useful in these circumstances.

I tried the expression (5 5 ⍴ ⍳ 25)[3 2; 1 2 3] in https://tryapl.org/ , and it returned

11 12 13
 6  7  8

I guess it makes sense for ivy to return this, too?

robpike commented 2 years ago

Oh, fair point. I misread your issue.

@rsc did the rewrite that got us here so over to him.

rsc commented 2 years ago

@fumin @robpike I opened #111 for the indexing question.

kpym commented 1 year ago

I noticed this is still open, presumably because of the 'need an Ivy discussion forum' part since the conditional execution now exists. One possibility would be to enable GitHub Discussions on this repo. We've used them for Go discussions that are expected to be too much for the issue tracker, and the single level of threading is really helpful.

We tend to only use them for big things in Go, but projects often use them now for Q&A etc. golang/go#47141 is one of our smaller discussions.

@rsc this can be moved to disucssions now ?