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

Record/list indexing #38

Open
foxfriends opened this issue Dec 5, 2020 · 1 comment
Open

Record/list indexing #38

foxfriends opened this issue Dec 5, 2020 · 1 comment
Labels
enhancement New feature or request
Projects

Comments

@foxfriends
Copy link
Owner

foxfriends commented Dec 5, 2020

It would be convenient to be able to access fields of a record similarly to in regular languages.

Having to use destructuring for everything is very verbose:

fullName(person { firstName: FirstName, lastName: LastName }, FullName) :-
  FullName <- FirstName + " " + LastName.

Where using field access could be simpler:

fullName(person(P), FullName) :-
  FullName <- P{firstName} + " " + P{lastName}.

This indexing operation would be not tied to variables, so a bit less useful but valid:

fullName(FullName) :-
  FullName <- { firstName: "Cam" }{firstName} + " " + { lastName: "Eldridge" }{lastName}.

Would also be useful to have a similar array access:

firstAndLastName(Names, FullName) :- 
  len(Names, N),
  FullName <- Names[0] + " " + Names[N - 1].

Could even chain accessors:

Record{field}[3]{anotherField}{lastField}

Wildcards/variables in records would be bound as usual:

name(Name, person(P)) :- 
  equal(P{name}, Name).

name("Cam", person { name: A }).
// A = "Cam"
@foxfriends foxfriends added this to RFC in Features via automation Dec 5, 2020
@foxfriends foxfriends moved this from RFC to To do in Features Dec 5, 2020
@foxfriends foxfriends added the enhancement New feature or request label Dec 5, 2020
@foxfriends foxfriends moved this from To do to In progress in Features Dec 10, 2020
@foxfriends foxfriends moved this from In progress to To do in Features Dec 11, 2020
@foxfriends foxfriends moved this from To do to RFC in Features Jan 28, 2021
@foxfriends
Copy link
Owner Author

foxfriends commented Feb 27, 2021

I am noticing that we don't really need indexing or updating, what we need is language level support for views

  1. Get a value at an path
  2. Set a value at a path
  3. Transform the value at a path

I do (3) very often (destructure a struct, transform a value, reconstruct it), so it would be nice to make all these steps super painless.

Views are a very functional-programming type idea though... maybe what I am doing is actually just something that needs a functional language...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

1 participant