nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

[Idea]: Shorten `component` to `comp` #605

Closed emil14 closed 1 month ago

emil14 commented 1 month ago

In JS we have function but in Go it's func, in Kotlin it's fun and in Rust it's just fn. I'm wondering if there's a language where it's just f.

Anyway. Should we shorten component? It's 9 characters, even bigger than "function". How about comp? That's probably the only way I can see it. It sounds also like a computer which also makes sense to me. Components is what does computation so it's a computer, yeah.

emil14 commented 1 month ago

99 Bottles example

Before

component Main(start) (stop) {
    nodes { Match<int>, next PrintNext2Lines }
    :start -> (99 -> next -> match:data)
    -1 -> match:case[0] -> :stop
    match:else -> next
}

component PrintNext2Lines(n int) (n int) {
    nodes {
        decr Decr<int>
        first PrintFirstLine
        second PrintSecondLine
    }
    :n -> first -> decr -> second -> :n
}

// === First Line ===

const {
    firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n'
    firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
    firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'
}

component PrintFirstLine(n int) (n int) {
    nodes { Match<int>, Println, Printf, Lock<int> }

    :n -> [match:data, lock:data]

    0 -> match:case[0] -> ($firstLine3 -> println)
    1 -> match:case[1] -> ($firstLine2 -> println)
    match:else -> [
        printf:args[0],
        ($firstLine1 -> printf:tpl)
    ]

    [println, printf:args[0]] -> lock:sig
    lock -> :n
}

// === Second Line ===

const {
    secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n'
    secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n'
    secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n'
    secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}

component PrintSecondLine(n int) (n int) {
    nodes { Match<int>, Println, Printf, Lock<int> }

    :n -> [match:data, lock:data]

    -1 -> match:case[0] -> ($secondLine4 -> println)
    0  -> match:case[1] -> ($secondLine3 -> println)
    1  -> match:case[2] -> ($secondLine2 -> println)
    match:else -> [
        printf:args[0],
        ($secondLine1 -> printf:tpl)
    ]

    [println, printf:args[0]] -> lock:sig
    lock:data -> :n
}

After

comp Main(start) (stop) {
    nodes { Match<int>, next PrintNext2Lines }
    :start -> (99 -> next -> match:data)
    -1 -> match:case[0] -> :stop
    match:else -> next
}

comp PrintNext2Lines(n int) (n int) {
    nodes {
        decr Decr<int>
        first PrintFirstLine
        second PrintSecondLine
    }
    :n -> first -> decr -> second -> :n
}

// === First Line ===

const {
    firstLine1 string = '$0 bottles of beer on the wall, $0 bottles of beer.\n'
    firstLine2 string = '1 bottle of beer on the wall, 1 bottle of beer.'
    firstLine3 string = 'No more bottles of beer on the wall, no more bottles of beer.'
}

comp PrintFirstLine(n int) (n int) {
    nodes { Match<int>, Println, Printf, Lock<int> }

    :n -> [match:data, lock:data]

    0 -> match:case[0] -> ($firstLine3 -> println)
    1 -> match:case[1] -> ($firstLine2 -> println)
    match:else -> [
        printf:args[0],
        ($firstLine1 -> printf:tpl)
    ]

    [println, printf:args[0]] -> lock:sig
    lock -> :n
}

// === Second Line ===

const {
    secondLine1 string = 'Take one down and pass it around, $0 bottles of beer on the wall.\n\n'
    secondLine2 string = 'Take one down and pass it around, 1 bottle of beer on the wall.\n'
    secondLine3 string = 'Take one down and pass it around, no more bottles of beer on the wall.\n'
    secondLine4 string = 'Go to the store and buy some more, 99 bottles of beer on the wall.'
}

comp PrintSecondLine(n int) (n int) {
    nodes { Match<int>, Println, Printf, Lock<int> }

    :n -> [match:data, lock:data]

    -1 -> match:case[0] -> ($secondLine4 -> println)
    0  -> match:case[1] -> ($secondLine3 -> println)
    1  -> match:case[2] -> ($secondLine2 -> println)
    match:else -> [
        printf:args[0],
        ($secondLine1 -> printf:tpl)
    ]

    [println, printf:args[0]] -> lock:sig
    lock:data -> :n
}
Catya3 commented 1 month ago

Yeah, every language seems to choose an id for this <= 4 characters. (func, def, fun, etc...). I think it's worth doing.

Other possible short words are unit, node, elem, part , com but they may be harder to get used to. comp does make sense in context.

emil14 commented 1 month ago

I like unit and (a little less) elem.

I was also thinking about def. In Python it stands for "define" and defines function. It could be used to define components as well.

emil14 commented 1 month ago

Another option could be to use word "module"

module Main(start) (stop) {
  // ...
}

or

mod Main(start) (stop) {
  // ...
}

Ofc we'll have to rename Neva's modules (that are same as Go's modules) to something else. Projects?

dorian3343 commented 1 month ago

Another option I like is to use the word "process" instead of component. It describes perfectly what we call a component, we process the data with them.

This could be shortened nicely to

proc Main(start) (stop) {
  // ...
}
emil14 commented 1 month ago

https://github.com/nevalang/neva/pull/659