Remove void "type"; convert statements to expressions
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 20/100
Direzione di ricerca
Non vengono indicati file, test o punti di ingresso. Inizia esaminando la gestione da parte del compilatore dei tipi restituiti void e delle istruzioni, quindi definisci la semantica del linguaggio e i test necessari per la mutazione fluente, i risultati booleani delle procedure e le definizioni con valore espressione prima dell’implementazione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Perhaps we should remove the use of void as a return type. Objects that perform an operation that modify themselves and don't necessarily have something to return can return themselves (similar to the builder pattern).
Example:
aList = [].add(1).add(2).add(3)
print(aList) // [1, 2, 3]
Procedures that aren't related to a class can always return a boolean indicating success or failure. We can even make the lack of a return be considered a success.
Example:
procedure1() {
a = 10
b = 10
c = a + b
print(c)
}
procedure1() // prints: '20', returns true
procedure2() {
number = readInt()
// This if "statement" would also technically be an expression that returns a boolean in this proposal
if (number % 2 != 0) {
// This can also be an expression maybe?
return false
}
}
procedure2() // < 1 returns false; < 2 returns true
It might encourage chaining procedures together like so:
checkCondition1(args) && checkCondition2(args) && checkCondition3(args) && doGuardedProcedure(args)
This is possible in the current state of LJ, but it might be further encouraged if we default return types to boolean (is this something we want to encourage?).
Presumably function definitions and class definitions would now also be expressions if we were strict about "no statements" which would mean LJ has first-class functions (and potentially lambdas).
function1 = main() { println("Hello, world!" }
function1() // "Hello, world!"
main() // "Hello, world!
function2 = (arg1, arg2) { printf("%s, %s", arg1, arg2) }
function2("cats", "dogs") // "cats, dogs"
function3(otherFunction, arg1, arg2) {
return otherFunction(arg1, arg2)
}
function3(function2, "cats", "dogs") // "cats, dogs"
class1 = Dog { ...class stuff... }
dog1 = class1() // Returns a new Dog instance
dog2 = Dog() // Returns a new Dog instance
class2 = { ...class stuff... } // LJ uses '{ }' for sets, so there needs to be some disambiguation here
object1 = class2()
someFactoryFunction(someClass, args) {
return someClass(args)
}
someFactoryFunction(class1, args) // Returns a new Dog instance
Treating everything like an expression feels more clear. It might seem odd to beginners that some funny words "return" stuff while other funny words "do" stuff. Some beginners have trouble figuring out when to use print() and when to use a return for example.
- Lingua principale
- Java
- Stelle
- 6
- Fork
- 7
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JMU-CS/less-java
-
cleanup help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
cleanup
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 45/100
-
cleanup enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 10/100
-
cleanup
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Add REPL Apertaenhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
Tutte le issue di JMU-CS/less-java
Issue simili
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Apertaarea/plugin
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
kestra-io/plugin-kestra#190 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
integra-team-red/meet-map#249 ·
-
[Studio][Bug] Cancelled create-user dialog keeps the password and admin switch for the next attempt Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
apache/rocketmq-dashboard#5064 ·