3
submitted 4 months ago* (last edited 4 months ago) by Tushta@programming.dev to c/concatenative@programming.dev

I wanted to map over a nested array in factor so I created a helper function:

: nested-map ( a quote -- a' ) swap [ over map ] map nip ;

which i then called with

{ { 1 2 } { 3 4 } } [ 1 + ] nested-map

But when I call it I get the error from the title.

If I just paste the body of the function it works as intended:

{ { 1 2 } { 3 4 } } [ 1 + ] swap [ over map ] map nip

So I guess I have two questions: is there a better way to achieve the original goal, but also how am I supposed to create higher order functions without getting this error?

you are viewing a single comment's thread
view the rest of the comments
[-] Tushta@programming.dev 2 points 4 months ago

Thanks to johnb on the Factor's discord channel I got answers to these two questions:

In terms of nicer way to do a nested map nicely, fried quotations are the answer:

'[ _ map ] map

and in order to call a quotation inside a word definition, one needs to use call( stack effect ) form:

: nested-map ( a quote -- a' ) '[ _ '[ _ call( x -- x' ) ] map ] map ;

this post was submitted on 01 Jul 2024
3 points (100.0% liked)

Concatenative Programming

145 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