Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op on a vector using text #100

Closed
hagna opened this issue Jan 17, 2022 · 2 comments
Closed

op on a vector using text #100

hagna opened this issue Jan 17, 2022 · 2 comments

Comments

@hagna
Copy link

hagna commented Jan 17, 2022

op pal x = t = '%d' text x; (rot t) *.== t

Is an attempt at palindrome, and it almost works:

pal 1001
1

pal 98
0

I expected:

pal 1001 1002
1 0

But I get

pal 1001 1002
0

The text operator seems to include spaces, so maybe that's part of the problem?

rho "%d" text 1 2 3
5
@robpike
Copy link
Owner

robpike commented Jan 17, 2022

This is related to #69, the lack of a way to force an operator on a vector to run an element at a time.

In the meantime, you can write a recursive loop:

op pal x =
	(rho x) <= 1: (rot t) *.== t = '%d' text x
	(pal x[1]), pal 1 drop x


pal 1
1

pal 234
0

pal 202
1

pal 202 301
1 0

@hagna
Copy link
Author

hagna commented Jan 17, 2022

Oh nice!

Oh right @rsc mentions "tail recursion" in #69.

In light of this personal lesson and #69, I'll close.

Thanks

@hagna hagna closed this as completed Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants