5 ms·
Uiua: A minimal stack-based, array-based language
- maximilianroos 3y agoThis is really cool — great work. J & APL are elegant but not easy to get started with, and difficult to install. This looks like a newer, nicer, more open version. Would be great to see some Advent of Code puzzles in Uiua..
- aarroyoc 3y agoBQN is also easier to get started. It's the only array language I ever tried because of that. Uiua seems to be inspired by BQN but it's also a stack-based language (BQN isn't).
- jonahx 3y agoIt seems heavily inspired by BQN, even the style of the web page.
- vanderZwan 3y agoCorrect: > The main language that inspired Uiua is BQN. While I had heard about APL before, BQN was my first real exposure to the power of the array paradigm. I think the language is an astounding feat of engineering. Marshall is both a genius and a great communicator. https://www.uiua.org/docs/design https://www.uiua.org/docs/design Also, a week ago there were only two contributors to the project: 1000+ by kaikalii, and this single commit by Marshall: https://github.com/uiua-lang/uiua/pull/1/files https://github.com/uiua-lang/uiua/pull/1/files
- queuebert 3y agoThis is exciting because it looks like BQN, but BQN had some unfortunate syntax in a few places. Edit: I'll be specific. Stranding required a special character in BQN '‿', but appears to be just '_' in Uiua.
- cl3misch 3y agoHmm, '‿' looks much nicer to me than '_' ... /s
- stainablesteel 3y agowingdings as a coding language
- shric 3y agoMy recent exposure to array programming languages came via a podcast called The Array Cast[1] Not affiliated, just recommending. The regular co-hosts appear to each be experienced with various array languages such as J, APL, etc. They don't get deeply technical, but it's a nice introduction, especially on explaining the appeal. A recent episode had Rob Pike (UTF-8, Go, etc.) on to talk about his array based calculator, Ivy[2] [1] https://www.arraycast.com/ https://www.arraycast.com/ [2] https://github.com/robpike/ivy https://github.com/robpike/ivy
- haolez 3y agoCan array languages be used as general purpose languages in any practical way? Or are they really only strong as calculators?
- hoosieree 3y agoThey can be. I know J has libraries for databases, image, audio processing, etc. I've written an assembler in J and translated it to K. The array languages are pretty decent for prototyping machine learning stuff. Often you don't need any libraries at all. Here's a 2-layer perceptron, first in Python+NumPy: import numpy as np X = np.array([[0,0,1], [0,1,1], [1,0,1], [1,1,1]]) y = np.array([[0,1,1,0]]).T np.random.seed(1) w0 = 2*np.random.random((3,4)) - 1 w1 = 2*np.random.random((4,1)) - 1 for j in range(10000): l1 = 1/(1+np.exp(-(X @ w0))) l2 = 1/(1+np.exp(-(l1 @ w1))) l2_error = y - l2 l2_delta = l2_error * l2 * (1 - l2) l1_error = l2_delta @ w1.T l1_delta = l1_error * l1 * (1 - l1) w0 += X.T @ l1_delta w1 += l1.T @ l2_delta print(np.round(l2,3)) [[0.007] [0.991] [0.992] [0.01 ]] And again in J: input =: 4 3 $ 0 0 1 0 1 1 1 0 1 1 1 1 target =: 4 1 $ 0 1 1 0 dot =: +/ .* sig =: {{ %>:^-y }} train =: {{ 'ignore_me w0 w1' =. y l1 =. sig input dot w0 l2 =. sig l1 dot w1 l2_error =. target - l2 l2_delta =. l2_error * l2 * 1 - l2 l1_error =. l2_delta dot |: w1 l1_delta =. l1_error * l1 * 1 - l1 w0 =. w0 + (|:input) dot l1_delta w1 =. w1 + (|:l1) dot l2_delta l2;w0;w1 }} 5j3":0{::train^:10000 {{<:+:?.y$0}} each 1 ; 3 4 ; 4 1 0.009 0.990 0.990 0.011 Here's that assembler (for the Nand2Tetris assembly language) in K. It's intentionally golfed. L:({x^"\r "}'*'"/"\'0:0)^,"" T:(("R",'$!16)!!16),(($`SCREEN`KBD`SP`LCL`ARG`THIS`THAT)!16384,24576,!5),((-1_1_)'L@&i)!{x-!#x}@&i:"("=*'L T,:n!16+!#n:?(({$[("@"=*x)&^`I$1_x;1_x;`]}'L)^!T)^` C:(" "\"D&A D+A A-D D !D D-1 -D D-A D|A D+1 0 A !A A-1 -A A+1 -1 1")!0 2 7 12 13 14 15 19 21 31 42 48 49 50 51 55 58 63 D:$`" "`M`D`MD`A`AM`AD`AMD J:$`" "`GT`EQ`GE`LT`NE`LE`MP B:{,/$(x#2)\y} P:{c:*d:|"="\*j:";"\x;"111",/(B.7,(64*|/"M"=c)+C@"A"/"M"\c;B.3,D??d 1;B.3,J??1_j 1)} `0:({(P;{"0"^-16$,/$2\(`I$1_x)^T@1_x})[2/"@"=*x;x]}'L)@&~i
- camel-cdr 3y agoI love the clear grouping of the of color coding.
- SnooSux 3y agoLMAO the trans flag colors for the transpose operator
- thesnide 3y agoI wonder if someone made a language where color matters...
- sondr3 3y agoYou’ll love Piet (https://esolangs.org/wiki/Piet https://esolangs.org/wiki/Piet) then :)
- thesnide 3y agoOhhhh. Did not know that one. thanks!
- ithkuil 3y agohttps://colorforth.github.io/cf.htm https://colorforth.github.io/cf.htm
- alexisread 3y agohttps://www.concatenative.org/wiki/view/colorForth https://www.concatenative.org/wiki/view/colorForth
- j-pb 3y agoNot sure if a joke referencing ColorForth. If not, ColorForth.[1] 1: https://en.m.wikipedia.org/wiki/ColorForth https://en.m.wikipedia.org/wiki/ColorForth
- thesnide 3y agoIt was. Congrats _o/
- diogenes4 3y agoI'm a big fan of stack-based languages conceptually, but they always seem to fall flat when it comes to basic reading comprehension. APL has the same issue, as does J. Factor did improve on this a little bit by eschewing the symbol fetish but it was still very difficult to rapidly scan the code for functionality. I'm not convinced the approach shown here is a good pairing with the human brain.
- poulpy123 3y agoI'm always wondering what kind of people prefer this syntax to more classical syntax
- rscho 3y agoThose iterating quickly on experimental stuff, or simply because arrays are the only needed collection (there are many such problems)
- xmcqdpt2 3y agoHot take: people who don't touch type.
- WorldMaker 3y agoOh, you can touch type emoji and symbols today. There are all sorts of interesting Input Method Editors (IMEs) for them. Since Windows 10 there's one by default in Windows if you type Win+. or Win+; (whichever you prefer). You can type and it will filter the emoji by name. It's not quite as nice for mathematical symbol entry, but it does include them (on the tab labeled with an Omega) and is still better than many other input methods for them. macOS has a similar out-of-the-box IME (Control+Command+Space), though it differs on the amount of math symbol support. Linux's most used IME subsystem `ibus` (specifically `ibus-emoji`) if correctly setup should also by default provide an experience for emoji (Super+. like Windows). There are third-party ones as well for most platforms. Emoji is not just for tap-typing/swipe-typing mobile users. (Also, I think it is really handy as developer to learn your local emoji IME: including emoji in test data is really handy for checking unicode safety in your applications and regularly using any IME at all while in your applications helps you test some accessibility issues that might affect users that must use an IME for there language such as CJK languages and Braille writers and more. English software developers get to overlook a lot of how languages around the world work and can easily break accessibility needs with bad assumptions and it is great that emoji are a grand field leveling tool to bring those experiences to us English speaking developers in a way we can easily "read"/"write".)
- huhtenberg 3y agoHmm, so ⌊×10[⍥^999] yields a list of numbers, but ⌊×10[⍥^1000] yields an audio clip. That's somewhat unexpected. The ^ above stands for the 3-dot cube dice glyph, which gets eaten by the HN backend, so it's ^ instead.
- hoosieree 3y agoThat surprised me too, but then I decided it was actually kinda brilliant. The alternative for when an array is "too big" to display is usually something like [1 2 3 ... 99999] Which is unsurprising, but not very usable. Audio is useful!
- 22c 3y agoFWIW that's only the case for the website, in the local interpreter mode there appear to be specific functions for rendering a bunch of numbers as audio/images. https://www.uiua.org/docs/&ap https://www.uiua.org/docs/&ap https://www.uiua.org/docs/&imd https://www.uiua.org/docs/&imd
- datadeft 3y agoThis is shows that you cannot make a language in the vacuum. There are other places and services that you need to integrate with and the use of these glyhps is making it harder. I think using simple words: find, reverse, etc. is probably a better option.
- WorldMaker 3y agoOr it proves that HN's unicode stripping and intentional emoji blocking is making it harder than necessary to communicate some math and programming topics in their preferred notations. (Also, this language supports the "simple words" approach but autoformats to the glyphs for final "readability".)
- vanderZwan 3y ago> The ^ above stands for the 3-dot cube dice glyph, which gets eaten by the HN backend, so it's ^ instead. Just write "random" instead, then the snippet is copy-pasteable to the web-based interpreter. That's how you would normally write it out anyway, and interpreter will turn that into the dice glyph when run.
- yoyohello13 3y agoThis is actually pretty neat. But I'm having a hard time understanding how to ergonomically write with glyphs. What's the intended workflow. Remembering a bunch of shortcuts to get ⌕ instead of just typing `find` seems harder to read and write. Edit: I think I understand from the language tour. You're supposed to write the ascii names like `find` then running the program converts built-ins to glyphs.
- trenchgun 3y agoOther way would be to have a dedicated keyboard
- vanderZwan 3y agoIt's basically "the auto-formatter takes care of it, and integrated highlighting makes it easy to remember what each glyph does until it's memorized". Imagine if gofmt or prettier actually replaced built-in function names.
- WorldMaker 3y agoAlso, the editor in the language has an expandable dedicated glyph panel (click the "Show Glyphs" or "Hide Glyphs" button on the upper right; on the front page it is expanded by default in the top example and the Pad editor page but then hidden on the rest of the embeds). That glyph panel is pretty neat because it also serves as a language reference and you can ctrl+click into the documentation pages.
- adamredwoods 3y agoWhy not just use a compiler then? Is a glyph, in the way it is used here, the same as a bytecode?
- deleted 3y ago[deleted]
- ithkuil 3y agoBeautiful. I'm a bit surprised by [1 2 ; .] 3 Producing [1 2 3] Instead of 3 [1 2]
- iFreilicht 3y agoEvery function has to pop all its inputs from and push its output to the stack. the duplicate (or .) function pops one input and pushes it twice. That is a little surprising, but making stack operations special in that they don't need to pop their arguments might be a worse option.
- jkafjanvnfaf 3y agoThis does look quite nice. I always felt that the operator precedence / association rules in other stack languages were by far the most difficult thing to get used to, not the nonstandard symbols. This appears more inviting in that regard. I do have to question the choice of right-to-left (array language) evaluation order. I've personally always preferred left-to-right (stack language) evaluation. I feel like right-to-left requires you to think to the end of a line before you start typing anything at all, as the first thing you type is the last thing that's evaluated. Left-to-right would also allow re-evaluating and visualizing the stack as you write each operator.
- alexisread 3y ago...Swap your language prefs to say, arabic? ;) More seriously though, I think it depends what your background is. Maths works in prefix notation eg. f(g(x)) but I appreciate that you can hold the stack in your head easier with postfixLR. Many people who are used to lisp would probably prefer prefix notation. non-stack or array langs have a nice tradeoff that you can look at the code without having to keep a model in your head, notably many forth users annotate their code with stack diagrams to help. Personally I'm quite taken with rebol syntax, passing a stack/array as the rightmost operand. http://blog.hostilefork.com/rebol-vs-lisp-macros/ http://blog.hostilefork.com/rebol-vs-lisp-macros/
- aebtebeten 3y agoSee https://lobste.rs/s/qygnov/uiua_concatenative_array_programming#c_xzzx7g https://lobste.rs/s/qygnov/uiua_concatenative_array_programm...
- sullyj3 3y ago> I feel like right-to-left requires you to think to the end of a line before you start typing anything at all Maybe this will make people tend to shorter lines, counterbalancing the natural tendency towards incomprehensibility of array and stack languages
- ithkuil 3y agoThe choice of symbols is brilliant! ♭ deshape flattens an array into a 1D array.
- jhvkjhk 3y agoI fell in love with it immediately after I clicked the button that say its name.
- smabie 3y agoIf anyone's interested, I made a similar language, but inspired by k/q instead: https://cryptm.org/xs/ https://cryptm.org/xs/ example fibanacci fn: fib:(n:(neg 1)+;0@n do(2 enlist 1@x sum x~)[0 1]);
- kaikalii 3y agoOh hey, I made this. Cool to see it at the top of HN!
- abrookewood 3y agoIt looks unlike anything I've ever seen before. Are there any other languages that use glyphs so heavily? What was your inspiration? I have no idea how I would use this language, but it's put a smile on my face. Amazing work.
- bradrn 3y ago> Are there any other languages that use glyphs so heavily? This is the case with most of the languages in the APL family, but especially APL [1] and BQN [2]. [1] https://en.wikipedia.org/wiki/APL_(programming_language) https://en.wikipedia.org/wiki/APL_(programming_language) [2] https://mlochbaum.github.io/BQN/index.html https://mlochbaum.github.io/BQN/index.html
- jonahx 3y ago> Are there any other languages that use glyphs so heavily? APL (the first, invented in the 1960s): https://en.wikipedia.org/wiki/APL_(programming_language) https://en.wikipedia.org/wiki/APL_(programming_language) BQN (a modern APL, looks like an inspiration for Uiua though I don't know): https://mlochbaum.github.io/BQN/ https://mlochbaum.github.io/BQN/ Too many smaller esoteric languages to count.
- 627467 3y agoHoon? https://developers.urbit.org/reference/hoon/rune https://developers.urbit.org/reference/hoon/rune
- keyle 3y agoLove the `?` "wut" for conditionals :) I shall call all instances of ternary conditionals "wut" statements now.
- derefr 3y ago
- theogravity 3y agoThe usage of symbolism is neat, but it wasn't intuitive that I had to evaluate it from right to left as opposed to left to right.
- nxobject 3y agoIf we're using this comments section as an informal feedback page, +1 to that. My mental model of stack-based languages are imperative, and it's strange when lists of actions read in reverse order. I may as well write a preprocessor that switches terms from RTL to LTR, as well as stick to spelling out the full names of operators, and see how far I get before I see why the original author made these decisions.
- jacknews 3y agoMy eyes! no, my brain!
- Minor49er 3y agoThis sounds cool, but every page just says "Loading..." on Firefox Mobile
- GaggiX 3y agoNot in my case, it works just fine. (Always using Firefox Mobile)
- zelda-mazzy 3y agoWell this is neat. In an odd way it reminds me of how Assembly uses short commands, but instead of 1-4 letter cmdlets it's just symbols, but with many more arrays. It makes for a visually interesting codebase. The thing that stands out the most to me is how the language itself functions as a work of art.
- transfire 3y agoReminds me a bit of Cognate[https://github.com/cognate-lang/cognate/blob/master/INTRODUCTION.md https://github.com/cognate-lang/cognate/blob/master/INTRODUC...] Think I would like Uiua more if it required a space between terms. It wouldn’t be quite as tacit but it would be easier to read and more flexible — you could have multi-symbol operators.
- ivanjermakov 3y agoI had no experience with array languages and decided to give it a try. It took me 4 hours to write FizzBuzz using only Uiua docs for help: # create an array of number 1-100 ns ← ∵(+1)⇡[100] # make a copy of it in a string form "1"-"100" nsStr ← ∵(□$"_") ns # every i % 3 == 0 is replaced with "Fizz", everything else is "" f ← ∵(□▽∶ "Fizz" =0◿3) ns # every i % 5 == 0 is replaced with "Buzz", everything else is "" b ← ∵(□▽∶ "Buzz" =0◿5) ns # every i % 3 == 0 && i % 5 == 0 is replaced with "FizzBuzz", everything else is "" fb ← ∵(□▽∶ "FizzBuzz" × =0◿5∶ =0◿3 .) ns # combine them into a 2D array gs ← [nsStr f b fb] # run a columnwise map # | pick the greatest string of each column # | | ⍉ ≡ (⊡⊢⇌⌂.) ⍉gs Inability to use maximum function with arrays of different sizes is a bummer, I had to workaround it with grade and pick.
- vanderZwan 3y agoThat's a good start! I'm not exactly great with array langauges myself, but I think it's simpler to fill an array with □"Fizz", one with □"Buzz", one with □"FizzBuzz", then create another indexing array and use pick: ⍉[∵(□$"_"+1)⇡100 [⍥.99□"Fizz"] [⍥.99□"Buzz"] [⍥.99□"FizzBuzz"]] +∵(×2=0◿5+1)⇡100 ∵(=0◿3+1)⇡100 ≡⊡ ⍉ There are probably a few more simplifications experienced array programmers can apply.
- ivanjermakov 3y agoSmart!
- zellyn 3y agohttps://code.jsoftware.com/wiki/NYCJUG/FizzBuzz https://code.jsoftware.com/wiki/NYCJUG/FizzBuzz gives a solution in J of: FB=:((0 i.~15 3 5|]){::'FizzBuzz';'Fizz';'Buzz';":)"0 FB i.100 I unfortunately don't know enough J or Uiua to be able to translate that Perhaps someone else can step in!
- vanderZwan 3y agoLuckily the Uiua language creator stepped in to help us out :)
- nxobject 3y agoFun weekend project: see how well I can write some Unixy utilities that work stdin -> stdout on text-based files.
- rickydroll 3y agodamm, looks like the love child of apl and forth printed out by a Selectric typewriter
- peter_d_sherman 3y agoWhat an interesting and pleasing little language! I like the use of non-ASCII Unicode glyphs and symbols for some functions/commands. It makes me wonder why (since we now have rich graphical user interfaces as opposed to monochrome ASCII command-line dumb terminals that were prevalent in the mid-early history of computers) more languages don't support those. On a related note, I think it would be interesting to research computer languages which were developed in base languages that are not English, i.e., any computer languages originating out of India, Russia, China, Japan, etc. -- to name a few... Maybe there's such a thing as an Esperanto programming language... Getting back to symbols though, a future society might implement a purely symbol based programming language. Were ancient Egyptian hieroglyphs -- a programming language for a computing architecture that has vanished in the depths of time? One can only speculate! We do know that in our current day there are programming languages like Mathematica, where Math symbols can be used in lieu of English(y) code, and there may be a trend to more symbols replacing ASCII named/spelled keywords and functions in our code in languages of the future... The use of symbols to replace words might result in smaller tighter, more readable code -- but (I'm thinking from the perspective of a future society here) it also might sever the bridge to computing's past... Which may be desirable to have, IF that future society would want to resurrect computers and compuation from a future apocalyptic event... But perhaps I'm thinking too hard about all of this... Interested parties may want to check out the following video: "Why are these 32 symbols found in caves all over Europe | Genevieve von Petzinger": https://www.youtube.com/watch?v=hJnEQCMA5Sg https://www.youtube.com/watch?v=hJnEQCMA5Sg Or, fast forward to this point to see the 32 symbols: https://youtu.be/hJnEQCMA5Sg?t=403 https://youtu.be/hJnEQCMA5Sg?t=403 Also, here is a great tutorial page for people who are new to stack-based languages: https://skilldrick.github.io/easyforth/ https://skilldrick.github.io/easyforth/ Anyway, Uiua looks very nice!
- WorldMaker 3y agoSpeaking of ancient hieroglyphs, there is a long lineage of symbol-based languages and it is interesting to follow their ebb and flow over time: APL is one of the oldest languages, existing alongside contemporaries like COBOL. In the ancient mainframe era when everything was up for grabs and few things felt set in stone (including character encodings and the format of punch cards, and the sorts of keyboards used to punch those cards) APL was there trying to save punch card space (but not keyboard space, there were some huge APL-focused keyboards) by using a heavily math notation-influenced symbolic language. Of course, as such things go, APL's appeal fell as the mainframe world settled on EBCDIC or ASCII (depending on if you were an IBM shop or not) as a "universal" character encoding and also as saving punch card space was less of a problem as other storage systems became more prominent. Uiua seems a fun "emoji-native" take on "your grandmother's" APL. (BQN is generally cited as among the first "Unicode-native" in the APL family. Beyond the stack language changes as neither APL nor BQN are stack languages, Uiua swaps some niftier emoji-based choices for operators that feel fresher and less "ancient math hieroglyphics" and little bit more "texting your modern friend who in this case is a computer" hieroglyphics.)
- aristus 3y agoI have no comment other than that the editor demo, when rendered on a phone, looks like a game of Space Invaders. It's glorious.
- ramon156 3y agoSo my biggest question is, what can I use this for? I get most languages start as fun hobby projects, but there must be some thought behind this concept right?
- gpm 3y agoSome people really like the idea of concatenative languages. I think this is probably reasonably viewed as "research into making those actually usable", in addition to a fun hobby project. Here's a blog post that tries to motivate them: https://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html https://evincarofautumn.blogspot.com/2012/02/why-concatenati... Here's another interesting recent attempt: https://www.dawn-lang.org/posts/introducing-dawn-(part-1)/ https://www.dawn-lang.org/posts/introducing-dawn-(part-1)/
- junke 3y agonb. emacs-calc is also stack-based and array-based