[Feature Request] Const Parameters

Abierto
#119 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
lua
Área
compilers

Línea de trabajo

Comienza rastreando cómo el compilador gestiona los parámetros de función y las variables const mostradas en test/main.yue. Compara la compilación con --target=5.1 y --target=5.4, y luego verifica que se acepte un parámetro const y que se rechace asignarle un valor, de acuerdo con el comportamiento existente de las variables const.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Lua
Estrellas
620
Forks
45
Merge medio
9 h 5 min
PR fusionados (30 d)
1

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de IppClub/YueScript

Todos los issues de IppClub/YueScript

Issues similares

Más issues de Lua

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.