Shorthand syntax to avoid verboseness #304

Closed
opened 2025-12-30 01:23:19 +01:00 by adam · 4 comments
Owner

Originally created by @LukasPrediger on GitHub (Apr 24, 2025).

Currently pkl is a pretty verbose language when writing simple constructs. It scales well but in the lowest regions i find myself writing a lot of extra code.

I think adding some syntax that allows for easier construction of primitive collections would already help.

Currently when i want to make a Listing of strings i have to write

foo = new Listing {
  "a"
  "b"
  "c"
}

It would be much nicer to be able to just write foo = ["a", "b", "c"]

I don't know if there's already a function that allows me to something similar and i missed it but for now having to write a lot of extra code is my biggest downside of using pkl (which is otherwise a very good language for its usecase)

Originally created by @LukasPrediger on GitHub (Apr 24, 2025). Currently pkl is a pretty verbose language when writing simple constructs. It scales well but in the lowest regions i find myself writing a lot of extra code. I think adding some syntax that allows for easier construction of primitive collections would already help. Currently when i want to make a Listing of strings i have to write ``` foo = new Listing { "a" "b" "c" } ``` It would be much nicer to be able to just write `foo = ["a", "b", "c"]` I don't know if there's already a function that allows me to something similar and i missed it but for now having to write a lot of extra code is my biggest downside of using pkl (which is otherwise a very good language for its usecase)
adam closed this issue 2025-12-30 01:23:20 +01:00
Author
Owner

@bioball commented on GitHub (Apr 24, 2025):

Generally, you'd define a module that just describes your schema:

// MySchema.pkl
foo: Listing<String>

Then you'd define your data:

amends "MySchema.pkl"

foo {
  "a"
  "b"
  "c"
}

In this case, adding = new Listing is redundant because you are already amending an empty listing.

@bioball commented on GitHub (Apr 24, 2025): Generally, you'd define a module that just describes your schema: ```pkl // MySchema.pkl foo: Listing<String> ``` Then you'd define your data: ```pkl amends "MySchema.pkl" foo { "a" "b" "c" } ``` In this case, adding `= new Listing ` is redundant because you are already amending an empty listing.
Author
Owner

@StefMa commented on GitHub (Apr 24, 2025):

I guess he is more asking about a syntax of creating a list in a single line. Like most programming language do.

So probably
foo = new Listing { "a", "b", "c" }
would satisfy him.

But this is just not possible with pkl...

@StefMa commented on GitHub (Apr 24, 2025): I guess he is more asking about a syntax of creating a list in a single line. Like most programming language do. So probably `foo = new Listing { "a", "b", "c" }` would satisfy him. But this is just not possible with pkl...
Author
Owner

@HT154 commented on GitHub (Apr 24, 2025):

Semicolons can be used as element/entry/property separators for "inline" object bodies:

foo: Listing = new { "a"; "b"; "c" }
@HT154 commented on GitHub (Apr 24, 2025): Semicolons can be used as element/entry/property separators for "inline" object bodies: ``` foo: Listing = new { "a"; "b"; "c" } ```
Author
Owner

@bioball commented on GitHub (May 7, 2025):

Closing this; the syntax is already pretty short, and not likely to change.

@bioball commented on GitHub (May 7, 2025): Closing this; the syntax is already pretty short, and not likely to change.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#304