Stream: beginners

Topic: Hey, can i only define variables once?


view this post on Zulip Jonas (Dec 05 2024 at 18:28):

Hey, can i only define variables once? Is there a way to change this behavior

view this post on Zulip Sam Mohr (Dec 05 2024 at 18:38):

So currently, shadowing is disallowed. We are working on changing that now that this proposal has been accepted:

https://docs.google.com/document/d/1Ly5Cp_Z7dY8KLQkkDYZlGCldxQj4jLzZ0vIeB-F8lJI/edit?usp=sharing

https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/.60for.60.20and.20.60var.60/near/471593157

It'll be at least a couple months before it's possible though

view this post on Zulip Sam Mohr (Dec 05 2024 at 18:39):

I'll probably be the one implementing most of that part of the proposal, so let me know if you have any questions!

view this post on Zulip Jonas (Dec 05 2024 at 19:02):

that's cool

view this post on Zulip Jonas (Dec 05 2024 at 19:02):

will for loops come too?

view this post on Zulip Jonas (Dec 05 2024 at 19:03):

it could be an really need alternativ to ocaml then?

view this post on Zulip Jonas (Dec 05 2024 at 19:03):

Does Roc have something like Ocaml References

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:04):

I think so.

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:04):

Yep, for loops will also come, I just don't know who is in charge of implementing them

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:04):

Jonas said:

Does Roc have something like Ocaml References

I don't think we are thinking about any sort of explicit mutability

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:04):

@Anthony Bullard I don't think we have refs?

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:05):

Sam Mohr said:

Anthony Bullard I don't think we have refs?

Sorry there I was speaking towards whether Roc could be an alternative to OCaml

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:05):

A ref is a value you can pass to other functions that is mutable. We don't currently have that, or plans for that

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:06):

We won't have arenas either, but we are already using RC instead of M&S or pause-the-world GC

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:07):

Or functors - but Module Params are an interesting alternative to that

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:07):

And I think I can feel good in saying we definitely won't have an object system :-)

view this post on Zulip Jonas (Dec 05 2024 at 19:09):

Sry, i am very new is Roc Pipe First or Last?

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:10):

PIpe first

view this post on Zulip Jonas (Dec 05 2024 at 19:10):

ok

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:10):

You should find the data structure for all module functions in the first position in all of the builtins

view this post on Zulip Jonas (Dec 05 2024 at 19:15):

are Records/Structs immutable as well?

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:16):

Yes

view this post on Zulip Jonas (Dec 05 2024 at 19:17):

:rolling_on_the_floor_laughing: then i still will have use for Ocaml, love how easy imports are and how fast

view this post on Zulip Jonas (Dec 05 2024 at 19:18):

in ocaml i have to precompile everything it takes a while

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:18):

The Roc compiler will be very fast compared to what you're used to, methinks

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:19):

It'll just take us some time to get it all tied together

view this post on Zulip Jonas (Dec 05 2024 at 19:19):

pkgs usallay complie to so files, so compliing the actual bin is quick

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:19):

I thought Dune was pretty fast at building, but it's been awhile

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:19):

But yes, Roc has different goals for Ocaml, they both have their uses

view this post on Zulip Jonas (Dec 05 2024 at 19:19):

meant the liabary files

view this post on Zulip Jonas (Dec 05 2024 at 19:19):

compiling them takes a while

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:19):

Will there ever be a Roc unikernel? :wink:

view this post on Zulip Jonas (Dec 05 2024 at 19:20):

but since they are precompiled dune just have to link them

view this post on Zulip Jonas (Dec 05 2024 at 19:21):

the std is written in Rust, i don't need an Rust Compiler right(have one installed anyways)

view this post on Zulip Jonas (Dec 05 2024 at 19:21):

even for basic-cli i guess

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:25):

I think the platforms ship with the .a files you need and then roc uses llvm to assemble it (or just links it with the appropriate linker)

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:25):

Here's the contents of basic-cli platform package:

Arg
Arg.roc
Cmd.roc
Dir.roc
Env.roc
EnvDecoding.roc
File.roc
FileMetadata.roc
Http.roc
InternalCommand.roc
InternalFile.roc
InternalHttp.roc
InternalPath.roc
Locale.roc
Path.roc
PlatformTasks.roc
Sleep.roc
Stderr.roc
Stdin.roc
Stdout.roc
Tcp.roc
Tty.roc
Url.roc
Utc.roc
glue.roc
libapp.roc
linux-arm64.a
linux-x64.a
linux-x64.rh
macos-arm64.a
macos-x64.a
main.roc
metadata_linux-x64.rm

view this post on Zulip Sam Mohr (Dec 05 2024 at 19:32):

Jonas said:

the std is written in Rust, i don't need an Rust Compiler right(have one installed anyways)

You should only ever need two things:

view this post on Zulip Richard Feldman (Dec 05 2024 at 19:41):

Anthony Bullard said:

We won't have arenas either, but we are already using RC instead of M&S or pause-the-world GC

also platforms can use arenas behind the scenes - e.g. doing one arena per request like @Folkert de Vries 's nea https://youtu.be/zMRfCZo8eAc?si=khwPJ-2BfTvuajYB

view this post on Zulip Jonas (Dec 05 2024 at 19:44):

can i concat a string from an List?

view this post on Zulip Richard Feldman (Dec 05 2024 at 19:44):

Jonas said:

are Records/Structs immutable as well?

semantically they're immutable, although roc does "opportunistic mutation" where things get automatically mutated in place (instead of cloned) if their refcount is 1, because then the mutation is unobservable and can safely be done as a silent performance optimization behind the scenes

more details at https://youtu.be/vzfy4EKwG_Y?si=rE4ZhW3n7Kx3iKZo

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:44):

Thanks for the clarification! Arena's are great for web requests

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:45):

Which is why even Go played around with it (I think it was removed though in 1.23

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:48):

Jonas said:

can i concat a string from an List?

Do you mean join a list of strings into one? Or a list of bytes (U8) into a string?

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:48):

The answer is yes on both

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:51):

Str.joinWith to join a (List Str, Str -> Str) and Str.fromUtf8 for (List U8 -> Str)

view this post on Zulip Anthony Bullard (Dec 05 2024 at 19:51):

https://www.roc-lang.org/builtins/Str#joinWith

view this post on Zulip Jonas (Dec 05 2024 at 21:38):

thanks


Last updated: Jul 06 2025 at 12:14 UTC