13 ms·
Show HN: ScrapScript – A tiny functional language for sharable software
Hi friends,
I started casually working on scrapscript in 2015. I built a few compilers over the years to test out various ideas/implementations, and I think I'm finally happy with the overall design.
The code is not public yet. Email me at hello@taylor.town if you're interested in joining the core team later this year.
Let me know if you have any questions or feedback :)
- chrismorgan 4y agoIn your styles: > pre { overflow-x: scroll; } `overflow: scroll` is very poorly named, and practically never the right tool. You want `overflow: auto` instead, which only renders scrollbars if they’re needed. (Long ago, there were two potentially valid scenarios for it: for avoiding reflow when changing the document’s length, and for unbreaking viewport units so that 100vw includes the viewport’s vertical scrollbar. The former was only exceedingly rarely useful, and can be achieved better now on all but Safari with the scrollbar-gutter property. The latter only Firefox ever implemented, and no one else wanted to, so they eventually removed it from the spec and from Firefox, so now viewport units are just stupidly broken by design. I myself have not found a single place I wanted to use `overflow: scroll` or where it would have been reasonable in the past decade. Stylesheet linters should include a default rule that complains about `overflow: scroll` because it’s so temptingly-named but so thoroughly not what you want.)
- layer8 4y agoIt’s the right tool when you prefer scrollbars to always be rendered, which is a valid preference. For example, in the “not needed” case, the scrollbar being rendered tells you at a glance that there’s no scrollable content with a hidden “only appears upon movement” scrollbar, an information which would otherwise be missing.
- chrismorgan 4y agoI’m completely confused by what you write, because it seems back-to-front. You seem to be speaking of platforms with overlay scrollbars that are invisible until you try scrolling; how does `overflow: scroll` behave differently from `overflow: auto` on such platforms? I would expect it to either be no different, or possibly to briefly show a completely misleading scrollbar briefly when the content appears. I think I must be missing something. Can you explain more what you mean?
- deleted 4y ago[deleted]
- substation13 4y agoHello! This looks really interesting to me. There is a feature I would like that I have never seen in a scripting language, and I wonder if Scrap might support it: > Monadic bind points and applicative join points in the script language Hopefully an example can convey what I mean. Bind: do { let! x = some_value_in_a_monad x + 1 } Applicative: do { let! x = some_value_in_a_monad and! y = another_value_in_a_monad (x + y) * y } Now when I embed this script, I would like my runtime interpreter to provide implementations of `let!` and `and!`. The script author defines the bind points and the runtime defines the effects. Is this possible in Scrap?
- andreypopp 4y agoOCaml has a similar thing but purely on syntactic level — http://jobjo.github.io//2019/04/24/ocaml-has-some-new-shiny-syntax.html http://jobjo.github.io//2019/04/24/ocaml-has-some-new-shiny-...
- surprisetalk 4y agoWow, I really like that syntax! Juggling lots of monads can be annoying. But to keep scrapscript small like json, this is something I would try to solve with editor tools rather than the language itself.
- substation13 4y agoHow should users write async, futures, option, result, etc. in Scrap? My hunch is that if you do not put the syntax into the language, then it will be hard for the community to standardize on one preprocessing tool. OCaml (which I am a fan of!) struggles with fragmentation here.
- surprisetalk 4y agoWith managed effects, all of the async stuff gets pushed over to the platform. I suspect that everybody will settle on a reusable `task` type, but each platform can determine its own async scheduling system. Consider this example: | "/home" -> q -> res:success <| "<p>howdy " ++ name ++ "</p>" , name = q |> dict/get "name" |> maybe/default "partner" | "/contact" -> _ -> res:success "<a href="mailto:hello@example.com">email</a>" | _ -> _ -> res:notfound "<p>not found</p>" . res = : success text : notfound text In this case, the platform creates a simple web server from the following type: text => query => res . res = : success text : notfound text Because scrapscript stays out of the scheduling game, the platform is free to run this code on as many cores and servers as it wants in parallel. But I 100% agree that community standardization is incredibly important! I just don't have a solution yet :) I will try my best to get everybody to work together though haha
- dangoodmanUT 4y agoSuper cool!!
- thrrwy007 4y agoeveryone says this is cool, but I didn't understand it at all, so embarrassing :(( please eli5, honestly, want to understand this, what is this and how is it useful?
- deleted 4y ago[deleted]
- will5421 4y agoOne cool thing, I think, is that you can do import foo/bar And foo's bar library will just work in your program without you having to download it then bundle it. It will just look for foo’s bar library online when it runs (and I guess it’ll be running on an online platform, not necessarily on your own computer).
- ivanjermakov 4y agoSounds quite dangerous...
- surprisetalk 4y agoIt's only dangerous in very predictable circumstances :) Type-safety guarantees that you won't get any side-effects where the types don't fit. And if you really want to run untrusted code, scraps are designed to be very easy to inspect :)
- zephraph 4y agoThis is incredible. I’ve been thinking a lot about personal software systems and a hypothesis that I have is that simpler code sharing/versioning mechanisms is key to greater agency in programming environments. I’m already a huge fan of unison (we had Rúnar on devtoolsfm) so I’m eager to explore scrap further.
- nightowl_games 4y agoI don't get it. Can someone use an example to demonstrate the value of this?
- surprisetalk 4y agoJust think of it as more powerful JSON :) You can send things around without converting everything into strings and objects that don't quite fit your use-case. Plus you have the added benefit of strong typing AND the ability to send those types to other systems. Most of the other features exist to make it nicer to use as a full programming language.
- aktuel 4y agoWhat a funny hoax.
- replwoacause 4y agoWhat does this even mean?
- aktuel 4y agoYou don't know what funny is our you don't know what a hoax is?
- al2o3cr 4y agoSince each function is independently versioned, how does ScrapScript deal with functions that need to upgrade together? For instance, suppose "foo" produces a structure and "bar" consumes it - what happens if the user passes the output of "foo version 10" to "bar version 1"?
- surprisetalk 4y agoIf the function output remains the same, then there are no breaking changes. If breaking changes occur, the type system will let you know :) Then you can either pin the function to an older version or fix the breaking changes directly. The language provides enough guarantees to make tooling that can handle most of this for the user automatically.
- carapace 4y agoNeat! Maybe check out the Joy programming language? It seems well-suited to this domain.
- surprisetalk 4y agoI'm definitely familiar with Joy. It's so elegant! I tried to make a concatenate sister language to scrapscript called "sewerscript", but there's only so much time in the world.
- azubinski 4y agoThis is perhaps too bright for the gloom of recent months here. Thanks to the author, this is a very exciting thing. Of course, ligatures without the "disable ligature under a cursor" extension are slightly weird, but it even adds charm, we're on a site "for hackers" (laughing). So, well, what kind of a ChatGPT can come up with something like that? :)
- motohagiography 4y agoThis is significant. There's so much I want to add, but I will wait until I can implement the things I needed this for in the actual code.
- TeeMassive 4y agoThis is fantastic. I can't count the number of hours I've wasted hacking away broken CI pipelines to fix broken links, passing data around through environment variables sorcery, runners and artifacts wizardry.
- dllthomas 4y agoIf you have any measure of success, you are 100% going to wind up with a thing in your ecosystem called "scrappy do"
- carterschonwald 4y agoLooks fun!
- lionkor 4y agoWould you mind publishing a EBNF or similar grammar spec? That would make the syntax clearer.
- surprisetalk 4y agoI'll be aiming for basic documentation and specs next. I first wanted to see if there was any community interest before dumping a ton of work into this project. I honestly didn't expect this much excitement :)
- acchow 4y agoWould love to see more of the type system described. If each scrap carries its own versions of its dependencies, then even the "same type" could actually be a "different type" because of version mismatches?
- surprisetalk 4y agoThe version isn’t considered when comparing types. If the types structurally fits into the spot, you’re good to go. I’m planning on publishing more of these kinds of details in the next month or two
- still_grokking 4y agoWhy the custom language? Building a language is already a lifetime project on its own… As I see it most of the more unique ideas could be implemented in form of some tooling on top of some existing languages. What do I overlook here?
- surprisetalk 4y ago> As I see it most of the more unique ideas could be implemented in form of some tooling on top of some existing languages. I deeply hope that's true, because it'll save me a lot of work :) Software doesn't seem to be getting better. In fact, it seems to be getting worse in many areas. Personally, I don't think there's "one big thing" that harms the ecosystem. I think it's friction in 1000 different places due to systems that don't quite work together seamlessly. Scrapscript is an attempt to vertically integrate all the lessons we've learned in software in the past 80 years.
- jayjader 4y agoVery interesting! I'm especially curious on how the live-coding experience plays out. I wish there was an example of a moderately-complex scrapbook, so that I could see what the code looks like when you start mixing several scraps and need a minimum of scaffolding.
- canadianfella 4y ago[dead]
- bibanez 4y agoI haven't fully understood this. Is this a way to share code? Where are the functions executed?
- surprisetalk 4y agoIt's a way to share code in multiple ways: - the language is like JSON, so you can send programs (and custom types) between computers - you can store code in public "scrapyards", and send references to the scraps for others to download later and reuse Code is executed on your machine, just like python, JS, etc.
- andybak 4y agoIt's late and I'm tired but this is one of the most interesting things I've seen in a while.
- mftb 4y agoSurprised, none of the more functionally minded have jumped in. Looks interesting, I'll be taking a look, when it ships.
- noduerme 4y agoI'm trying to wrap my head around the "magic compression" bit. So literally every namespace lives in a repo somewhere? And even files referenced are just automatically committed to that repository? What am I missing? Also how does this not create either an enormous tangle of circular references or a huge pile of unused... scrap?
- andyferris 4y agoIt’s content addressed, so circular references can’t naturally arise. You kind of need to create an ID of some sort and reference that and create some way of looking that up. I didn’t check if they allow for recursive function calls, etc. The repository/scrap pile of content could be stored in lots of ways that you could choose. I imagine if everyone pushed directly to a global “scrap pile” like IPFS it would end up as a huge pile of unused scrap. Like unison, they’d need to provide some kind of default development environment, but anyone could build additional tooling (kind of like anyone could write a git clone).
- panphora 4y agoSo it's like a social network with every type of relationship imaginable built into a low level programming language? That's wildly cool. This and Val Town [0] feel like they were made for each other. If you added them together with a nice front-end like mmm.page [1] I bet a million devs would sign up. I'm working on something in a similar space that I'm hoping mihht develop into that [2] It makes sense that the next step for the web is a more low-level social platform that works more like an agnostic API than a walled garden. [0] https://www.val.town/ https://www.val.town/ [1] https://build.mmm.page/ https://build.mmm.page/ [2] https://hyperspace.so/ https://hyperspace.so/
- dangoodmanUT 4y agoThank you I've been trying to find the build.mmm.page link again for a year but I couldn't remember the name of the site XD
- mstade 4y agoThe signal to noise ratio in your comment is off-the-charts awesome – thank you for the amazing links!!
- discardedrefuse 4y agoThanks for these links. Looks like I have a new rabbit hole to explore! Side note: I was just watching the val.town video and at the end he mentions that "you are an object" and other people can access your properties. It immediately made me think of playing hackmud. Not sure if that's a good thing or bad!
- xhfloz 4y agoHeyyo. Creator of mmm.page here. Fun to see it mentioned. In case it's of interest, I've been coming at this from a more GUI perspective: scriptable objects (like paper) [1] and social primitives [2]. Excited to see where this project goes. [1] https://paper.mmm.dev/ https://paper.mmm.dev/ [2] https://twitter.com/xhfloz/status/1611094168981458981 https://twitter.com/xhfloz/status/1611094168981458981
- deleted 4y ago
- thomasfromcdnjs 4y agoThis looks like a fun thing! It makes me feel like some hacker dweebs in the future would be communicating through this platform.
- sagebird 4y agoThis is lovely. I’ve had a vague notion that I wanted something like this… but never quite solidified my understanding of what is necessary. This is a super minimal-maximal example. Bravo. Do equivalent programs produce the same hash? Ie: a = 1 + 1 Return a Vs a = 2 Return a What if local internal variable names change? Ie b = 2 Return b
- sagebird 4y agoThinking a bit more: A-If a program is a thing that produces a result for a given input, these programs are the same. B-You can’t generally know if two programs are the same without solving halting problems, reducing polynomial algos to linear time or having infinite time and space computing resources, etc. C-The best you can do is ask if two compilers produce the same output, or a linting/refactoring/canonicalization/formatting operation results in same source. D-If a program is a thing that interactive debuggers use to create explorations next to source code while computing, these programs are different. I agree with your approach of starting with these programs as being different, and allowing custom scraps to become a higher layer hash resolver. The reason is that compilers change over time, and it is only under the lens of a compiler(or linter, etc) that comparisons can be made. To bake a holy compiler in today would be arbitrary and quickly outdated.
- xigoi 4y agoDue to the halting problem, it's not possible to tell in general if two programs are equivalent.
- amelius 4y agoAs far as I know, nobody ever proved that some programs for which halting cannot be determined are smaller in size than the number of atoms in the universe. Or in other words, that the theorem applies to practical programs. It's purely theoretical.
- xigoi 4y agoHere is a Python program which is definitely smaller than the number of atoms in the universe. Can you tell me whether it halts? n = 1 while sum(d for d in range(1,n) if n % d == 0) != n: n += 2
- amitlzkpa 4y agoThis is awesome. I had a shell of an idea like this that never got anywhere. Wasn't even sure if it were feasible. Really neat!
- quaintdev 4y agoNot 100% sure but there is another project with similar ideas https://www.unison-lang.org/ https://www.unison-lang.org/
- robinsord 4y agoIs this meant to be understood by geniuses or something? I'm halfway through reading about it and I still have absolutely no idea what any of this remotely means. Is the target audience for this genius hipsters who have 10,000 years of boilerplate context to even grok what the author is saying?
- jmholla 4y agoI agree. This whole page reads like nonsense to me. One easy example to point out: > # Optimized for AI & Autocomplete > ``` > f a b > . f = | x -> y -> x \* y > . a = 1 > . b = 2 > ``` > Scrapscript encourages wishful thinking[0]. > > Declare your goal up-front, and let your tooling make educated guesses about how to get there. What does the title, example, and text have to do with each other? None of them seem to be talking about the same thing. What does AI have to do with this? How are these single character variable enable autocomplete? What does wishful thinking have to do with anything here? I feel like I took crazy pills. Or maybe this is what having a stroke feels like. [0]: https://wiki.c2.com/?WishfulThinking https://wiki.c2.com/?WishfulThinking
- surprisetalk 4y agoYeah, I'm hoping to put out a more readable guide soon! I didn't have the time/energy to put much of the necessary explanations and groundwork in there. For this specific example, many languages have constructs like this: let x = 1 in f x Scrapscript flips things around: f x . x = 1 I stole the phrase "wishful thinking" from the SICP lectures, where Sussman encourages writing the important parts first as if the details existed. I think this syntax encourages writing the big-picture ideas first. For AI/autocomplete, tools like Github Copilot currently have to guess what you want from all the parts (e.g. variable names) you put on the table. By putting the variables last, the editor tooling can create boilerplate for your variables as you type. Let me know if there's anything else that might need extra explanation!
- tromp 4y agoHaskell uses keyword "where" for that. So the example corresponds to the following Haskell code: f a b where f = \x -> \y -> x * y -- or f = (*) a = 1 b = 2
- ivoras 4y agoNeat but... Someone will make a crummier version of this in a language which doesn't feature parts looking like Unicode white noise and the original authors will be frustrated why the crummier vetsion took off and their project didn't. Not every idea deserves to have an esoteric language attached to it to work.
- alwillis 4y agoI’ve been using fonts with ligatures for esoteric languages like CSS and HTML for years. ;-) Seriously, fonts that coders tend to use have included ligatures for quite a few years. For me, it’s less visual noise and a cleaner look. I use Vim/Neovim and WezTerm but there are many combinations of editors and terminal emulators that support ligatures. And many programmers fonts: https://github.com/ryanoasis/nerd-fonts https://github.com/ryanoasis/nerd-fonts
- runlaszlorun 4y agoI’ve been working on a crummier version. So crummy it will likely never make it to a v0.1… :)
- fernmyth 4y agoThe funny Unicode symbols are actually ASCII `->` and `|>` rendered in a font with ligatures. I agree it's a bit jarring to see, but you wouldn't need a special keyboard.
- andyferris 4y agoOhh… totally missed that!
- surprisetalk 4y agoThe font is Fira Code for anybody interested!
- beeburrt 4y agoJetBrains Mono does that ligature `|>` in my Elixir code. I like it :)
- haolez 4y agoLooks fun, but doesn't look like it will be open source. That's a shame, since it considerably raises the risk of adopting such a platform. EDIT: the author claims that it will be open sourced soon :)
- surprisetalk 4y agoAuthor here! It will be open sourced soon, but I’m embarrassed about my messy code :) Email me at hello@taylor.town if you’re interested in joining the team
- Bjartr 4y agoA rule of thumb is that if you're not embarrassed when you launch, you've waited too long.
- elbear 4y agoWhat are you building it in?
- surprisetalk 4y agoMy latest iteration uses a bootstrapped compiler written in scrapscript :) The bootstrapper was written in Elm, because its parsing combinator library is by far the nicest to use. I wrote a rust bootstrapper in ~2019, but it was much too heavy for my experimentation phase. I think rust would be a good candidate going forward for the bootstrapper going forward though. I'm open to suggestions!
- elbear 4y agoElm, a nice surprise. I don't have experience with writing compilers, so I can't suggest anything. I just know that Haskell is promoted as a language suitable for this kind of task. Have you looked at it?
- surprisetalk 4y ago
- eggy 4y agoI like the unique hash thing like Unison, but it also has an Urbit/Nock/Hoon vibe aside from IPFS one you mentioned. I'll check it out tomorrow. Ilike the examples and syntax. Types - yay!
- VTimofeenko 4y agoLooks extremely fun. Coming from nix background, content addressability of stuff is a huge win. Looking forward to be able to play with this.
- verdverm 4y agoWould the IPFS-ness of this make updating all the programs that suffer from an exploit or error a difficult thing? Kind of like smart contracts, once it is published, there is no changing it? So the chain of dependencies containing the exploit or error, make updating all of the consumers a pain.
- surprisetalk 4y agoThis is a great observation. By default, using a name like `janedoe91/fibonacci` pulls the latest version of that particular scrap from the scrapyard. But all of its references are baked-in unless the author updates them. The way around this is that consumers are empowered to use whatever forcing upgrade strategies they want. All scraps are transparent, so you can pipe everything through an "upgrader" scrap before execution, which replaces dependencies all the way down the stack with their latest versions. I'm sure many of these upgraders will exist depending on what types of tradeoffs you're looking for.
- verdverm 4y agoCan scraps be versioned? Is it possible to see the available versions of a scrap? Could you add support for dependency management? MVS is a nice and easy algo: https://research.swtch.com/vgo-mvs https://research.swtch.com/vgo-mvs
- surprisetalk 4y agoYes, scraps can be versioned: user/my-scrap@99 And you can check the available versions of the scrap by querying the scrapyard directly. But omitting the version will just use the latest: user/my-scrap Each scrap contains a full list of its own dependencies, so there is no need for external dependency management. All scraps are transparent, so you can create your own tools to manually tweak/replace dependencies before execution: $ cat my-scrap.ss \ | scrap apply my-dependency-helper \ | scrap eval
- verdverm 4y ago
- noman-land 4y agoThis is nuts and incredibly cool.
- crowdhailer 4y agoThis is very cool. I have similar goals with my own language. Though I am developing only and AST and no syntax because I would like to be able to embed the same language into visual programming environments. https://petersaxton.uk/log/ https://petersaxton.uk/log/
- leke 4y agoDid I miss the reference to the license? Looks interesting though. Would like play with this when it's released.
- offlinehacker 4y agoReminds me of what unison already does, I just wonder what will be license and scope https://www.unison-lang.org/ https://www.unison-lang.org/
- surprisetalk 4y agoI'm still not sure about the exact license yet, but everything will definitely be free and open :)
- snthpy 4y agoI like the high level ideas and goals. I still have to get my head around the syntax and how it works in practice but will definitely keep an eye on this!
- zubairq 4y agoAuthor of a framework that also stores it's code in IPFS for easy sharing (https://github.com/yazz/yazz https://github.com/yazz/yazz). ScrapScript is a really nice concept with how it stores code. I originally got the idea for storing the code as a hash of the contents from Unison, and it looks like the idea is really starting to catch on with more and more languages now. Well done!
- quickthrower2 4y agoOne question. If you reference a package by hash. Is there semantic versioning? Can you get security updates?
- surprisetalk 4y agoI'm currently planning non-semantic versioning (next versions just increment by 1), but I'm open to changing if I can figure out how to make semver efficient. I mention it here[1], but security updates can be performed by both authors and consumers. [1] https://news.ycombinator.com/item?id=35739161 https://news.ycombinator.com/item?id=35739161
- quickthrower2 4y agoI am not a super fan of semantic versioning (but it is "OK"). What I like is you can flag "breaking" vs "enhancement" vs "no api change". And "no api change" is usually always what you get with a security patch. Really you only need 2 versions in semantic version (my opinion): breaking.non-braking "next versions just increment by 1" might be good where you have a non-breaking change, and that would allow security patches to flow down.