Concatenative Programming

153 readers
1 users here now

Hello!

This space is for sharing news, experiences, announcements, questions, showcases, etc. regarding concatenative programming concepts and tools.

We'll also take any programming described as:


From Wikipedia:

A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition. Concatenative programming replaces function application, which is common in other programming styles, with function composition as the default way to build subroutines.

For example, a sequence of operations in an applicative language like the following:

y = foo(x)
z = bar(y)
w = baz(z)

...is written in a concatenative language as a sequence of functions:

x foo bar baz


Active Languages

Let me know if I've got any of these misplaced!

Primarily Concatenative

Concatenative-ish, Chain-y, Pipe-y, Uniform Function Call Syntax, etc.


Cheat Sheets & Tutorials

Discord

IRC

Wikis

Wikipedia Topics

Subreddits

GitHub Topics

Blogs

Practice

founded 1 year ago
MODERATORS
1
2
1
Derangements | Re: Factor (re.factorcode.org)
submitted 1 week ago by Andy to c/concatenative
3
3
Zen of Factor | Re: Factor (re.factorcode.org)
submitted 2 weeks ago by Andy to c/concatenative
4
3
Watching Code | Re: Factor (re.factorcode.org)
submitted 2 weeks ago by Andy to c/concatenative
5
14
submitted 2 weeks ago* (last edited 2 weeks ago) by Andy to c/concatenative
 
 

Alright, show me I'm not the only one in this community, and show off some solutions!

Here's my Day 1 solution in Factor (minus imports):

spoiler

: get-input ( -- left-list right-list )
  "aoc-2024.01" "input.txt" vocab-file-lines
  [ split-words harvest ] map unzip
  [ [ string>number ] map ] bi@ ;

: part1 ( -- n )
  get-input
  [ sort ] bi@
  [ - abs ] 2map-sum ;

: part2 ( -- n )
  get-input
  histogram
  '[ dup _ at 0 or * ] map-sum ;

Sadly, Factor doesn't get highlighted properly here, so here it is again as an image:

spoiler

syntax-highlighted screenshot of the code above

I probably won't last the week, but what solutions I do have will be up on GitHub.

6
6
NeoHaskell (neohaskell.org)
submitted 3 weeks ago by Andy to c/concatenative
 
 

This example is my justification for posting it here:

"NeoHaskell is cool"
  |> Text.toWordList
  |> List.map Text.length
  |> List.map (\x -> x * x)
  |> List.takeIf Int.isEven
7
8
 
 

I posted this project here before, but it's now reached 1.0.0.

9
2
submitted 1 month ago by Andy to c/concatenative
10
2
submitted 1 month ago by Andy to c/concatenative
11
 
 

Hey, it includes Factor!

12
4
Constants | Re: Factor (re.factorcode.org)
submitted 1 month ago by Andy to c/concatenative
13
 
 
14
4
submitted 2 months ago by Andy to c/concatenative
15
 
 

Animated preview

This is not my own project!

16
2
Emit | Re: Factor (re.factorcode.org)
submitted 2 months ago by Andy to c/concatenative
17
5
submitted 2 months ago by Andy to c/concatenative
 
 

Discussion on HackerNews

18
 
 

Slint is a GUI toolkit, and is largely not relevant to concatenative programming. But the latest release adds a touch of postfix to the mix, which is nice to see.

From the blog post:

Math Gains Postfix Support

A subtle but profound change to the language. Traditional syntax:

Math.max(20, Math.abs(value.x))

New postfix syntax:

value.x.abs().max(20)

The new syntax improves readability by making the transformation steps more explicit. It works well for many operations but has limitations:

Effective for simple transformations (e.g., abs, max) Less intuitive for operations like clamp or atan2.

pos.y.atan2(pos.x) // Less clear than atan2(pos.y, pos.x)

So for now you cannot use postfix for all functions in the Math namespace. We may revisit these cases later, so give them a try and let us know your thoughts.

19
20
6
Roc, Exercism, Forth! (isaacvando.com)
submitted 2 months ago by Andy to c/concatenative
21
2
Battlesnake | Re: Factor (re.factorcode.org)
submitted 3 months ago by Andy to c/concatenative
22
23
24
25
view more: next ›