IppClub / IppClub/YueScript

[Feature Request] Const Parameters

Open
#119 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
613
Forks
45
PR merge metrics
No merged PRs in 30d

Description

Since yuescript does support constvariables (for lua 5.4), I've been playing around with it for a little bit. However, one thing I noticed is that a const parameter cannot be created. I'm not sure if this a thing in lua 5.4 (I've done some Google searching, can't find it), but it would be ideal to allow const in parameters. For example:

test = (const a, b) ->
    a = 3
    return a + b

a = 1
const b = 2

print test a, b

I build this:

 ❯ yue.exe --target=5.1 test/main.yue
Built test/main.yue

It results in:

local test = (const(a, b))(function()
    local a = 3
    return a + b
end)
local a = 1
local b = 2
return print(test(a, b))

Now, even if I built it for lua 5.4, it results in the same compilation, which obviously const isn't supposed to be a valid function here, since I never defined it. I want that to mark the parameter as const so I cannot modify a, or whatever the parameter might be, in the function. I think it should be doable, honestly, because even compiling with const variables for lua 5.1 works perfectly fine, but if you were to modify the variable, yue refuses to build the source file as it should.

Even if const parameters don't exist in lua 5.4, it would be easy to add a check that the variable is marked as such in the parameter and refuse to build the file if you try to modify it, much like with a variable.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the compiler handles function parameters and the const variables demonstrated in test/main.yue. Compare compilation with --target=5.1 and --target=5.4, then verify that a const parameter is accepted and that assigning to it is rejected, matching the existing const-variable behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.