this post was submitted on 28 Mar 2024
4 points (100.0% liked)

Concatenative Programming

145 readers
2 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
 

Just because Exercism doesn't offer your favorite language as an official track, it doesn't mean we can't play at all. Post some solutions to the weekly challenges in the language of your choice!

you are viewing a single comment's thread
view the rest of the comments
[–] Andy@programming.dev 1 points 7 months ago (1 children)

Scrabble Score, again

USING: combinators kernel sequences sets unicode ;

MEMO: char>score ( char -- n )
  {
    { [ dup "AEIOULNRST" in? ] [  1 ] }
    { [ dup         "DG" in? ] [  2 ] }
    { [ dup       "BCMP" in? ] [  3 ] }
    { [ dup      "FHVWY" in? ] [  4 ] }
    { [ dup          "K" in? ] [  5 ] }
    { [ dup         "JX" in? ] [  8 ] }
    { [ dup         "QZ" in? ] [ 10 ] }
  } cond nip ;

: scrabble-score ( str -- n )
  >upper [ char>score ] map-sum ;

[–] Andy@programming.dev 1 points 7 months ago (1 children)

Scrabble Score, a third time

USING: assocs.extras kernel make sequences unicode ;

: scrabble-score ( str -- n )
  >upper
  [
    "AEIOULNRST" [  1 swap ,, ] each
            "DG" [  2 swap ,, ] each
          "BCMP" [  3 swap ,, ] each
         "FHVWY" [  4 swap ,, ] each
             "K" [  5 swap ,, ] each
            "JX" [  8 swap ,, ] each
            "QZ" [ 10 swap ,, ] each
  ] H{ } make
  swap values-of sum ;

[–] Andy@programming.dev 1 points 7 months ago (1 children)

Scrabble Score, 3.5

USING: assocs.extras kernel literals make sequences unicode ;

CONSTANT: charscores $[
  [
    "AEIOULNRST" [  1 swap ,, ] each
            "DG" [  2 swap ,, ] each
          "BCMP" [  3 swap ,, ] each
         "FHVWY" [  4 swap ,, ] each
             "K" [  5 swap ,, ] each
            "JX" [  8 swap ,, ] each
            "QZ" [ 10 swap ,, ] each
  ] H{ } make
]

: scrabble-score ( str -- n )
  charscores swap >upper values-of sum ;

[–] Andy@programming.dev 1 points 7 months ago

Scrabble Score 4.0

USING: assocs.extras kernel literals make sequences unicode ;

CONSTANT: charscores $[
  [
    { 1 2 3 4 5 8 10 }
    { "AEIOULNRST" "DG" "BCMP" "FHVWY" "K" "JX" "QZ" }
    [ [ ,, ] with each ] 2each
  ] H{ } make
]

: scrabble-score ( str -- n )
  charscores swap >upper values-of sum ;