Preskoči na glavno vsebino

Objave

Go's concurrency in a dynamic language Rye

  The Rye programming language is a dynamic scripting language based on REBOL’s ideas, taking inspiration from the Factor language and Unix shell. Rye is written in Go and inherits Go’s concurrency capabilities, including goroutines and channels. Recently, Rye gained support for Go’s select and waitgroups. Building blocks Goroutines Goroutines are lightweight threads of execution that are managed by the Go/Rye runtime. They operate independently, allowing multiple tasks to run concurrently without blocking each other. Creating a Goroutine in Rye is straightforward. The go keyword is used to launch a new Goroutine, followed by the Rye function to be executed concurrently. For instance, the following code snippet creates and starts a Goroutine that prints a message after a delay: ; # Hello Goroutine print "Starting Goroutine" go does { ; does creates a function without arguments sleep 1000 print "Hello from Goroutine!" } print "Sleepi...

New website, reference, documentation, VS Code extension ...

Work on testing and improving quality of Rye core continues. We keep unifying interfaces, adding missing type support to built-in functions, exception handling, doc-strings ... We are writing tests that autogenerate function reference : https://ryelang.org/basics.html A week or so ago I also created first proper front page for Rye. https://ryelang.org/ Fellow contributor keeps tweaking github actions to include Go linters, unit tests and other checks. He also added support for binary releases and binary docker images. https://github.com/refaktor/rye/releases/ - binary release https://github.com/refaktor/rye/pkgs/container/rye - binary docker image Now, since function reference is no way to understand the language itself I started writing bigger documentation effort, Meet Rye https://ryelang.org/meet_rye/ Rye structures is the most interesting page for now. There is also a first version of VS Code extension available that offers syntax highlighting. You can find it in VS Code Exten...

Talking in Rye over Telegram

Telegram is a popular messaging app that offers a variety of solid clients and features, including chatbots. In this blog post, we will explore how to create a Telegram chatbot that we can communicate with, in Rye language - yeah, we’re fans :=). Starting with an Echo Bot Our first step in creating a Telegram chatbot will be to create a simple Echo bot. An Echo bot simply echoes back whatever message it receives. This is a good starting point for learning how to create more complex bots. Setting up a new bot in Telegram involves interacting with the BotFather on Telegram itself to get a token, which you’ll save in a .token file. Rye uses Go’s telegram-bot-api library quite direct. With a few helper functions the example code could be shorter and more high level, but this better shows us what is going on behind the scenes.   So we load the API token, create an instance of the Telegram-bot and define its on-update method. In it we parse the ‘Message’ out of the JSON ...

Receiving emails with Go's smtpd and Rye

This goes a while back. At some project for user support, we needed to receive emails and save them to appropriate databases. The best option back in the day seemed project Lamson . And it worked well ever since. It was written in Python by then quite known programmer Zed Shaw. It worked like a Python based SMTP server, that called your handlers when emails arrived. It was sort of Ruby on Rails for email. We were using this ever since. Now our system needs to be improved, there are still some emails or attachments that don't get parsed correctly. That isn't the problem of Lamson, but of our code that parses the emails. But Lamson development has been passive for more than 10 years. And I am already moving smaller utilities to Rye.  Rye uses Go, and Go has this nice library smtpd , which seems like made for this task. I integrated it and parsemail into Rye and tested it in the Rye console first. Interesting function here is enter-console , that can put you into Rye console any...

Ryelang - controlled file serving example and comparison to Python

This is as anecdotal as it gets, but basic HTTP serving functions in Rye seem to be working quite OK. They do directly use the extremely solid Go 's HTTP functions, so that should be somewhat expected. I made a ryelang.org web-server with few lines of Rye code 3 months ago and the process was running ever since and served more than 30.000 pages. If not else, it  seems there are no inherent memory leaks in Rye interpreter. Those would probably show up in a 3 month long running process? And now I got another simple project. I needed to make a HTTP API for some mobile app. API should accept a key, and return / download a binary file in response if the key is correct. Otherwise it should return a HTTP error. So I strapped in and created Rye code below. I think I only needed to add generic methods stat and size? , all other were already implemented, which is a good sign. Of course, we are in an age of ChatGPT, so I used it to generate the equivalent  Python code. It used the ele...

Ryelang Reddit Group

If you are an occasional visitor of this blog, you maybe noticed, that I haven't posted in a while. This was not because of the lack of activity on my end though.  I started a Reddit group /r/ryelang at the end of February, and I was very active over there since then. I wrote over 20 Reddit posts on the group. Few examples: Adding Regexp to Ryelang Rye basics: a gentle introduction trough Python examples #1 Rye basics: a gentle introduction trough Python examples #2 Chat-like interface for the terminal in Rye Rye's Http server can now handle file uploads (example) Rye, meet GPT3 ... and vice versa :)    Spreadsheet datatype in Ryelang First version of Semantic search with Rye So, please visit our reddit group and if you are interested, comment, like and become a member! :) And some screenshots:    

Chat-like interface for the terminal in Rye

Rye is at this point focused on becoming a useful tool for use in Linux shell (the server/back-end tasks). So I integrate it with the libraries that make sense there and I also like to improve the whole terminal capability of Rye.   I got some idea (one of many of this kind, we will see how this one goes :P) that I could make a set of interactive tasks, that could teach my two kids (and others potentially) about how the computer works, and how you can work with a computer through Linux shell. For this I would need some sort of interactive terminal based user interface, I imagined something chat like. See how the "game" looks in action with asciinema . Above is a small demo of the idea after a day of work on it. It's in form o a very very small text based adventure game :). To make this work I needed to create basically 2 functions, chat (and chat-lines for now) and choice. I wanted to use short, context specific words to do all this so I created it inside a chat-tui co...

Ryelang Reddit group and Ryelang org domain, focus ...

Reddit After a motivating email by my unofficial handler :) (@otobrglez), I decided to move Rye up another step again. In the past, he also pushed me to put Rye on github , make it more orderly and presentable, able to run on docker, and other such bad things :). A reddit group was created /r/ryelang . You are welcome to check it out, join, like and comment on things: reddit.com/r/ryelang/ To kick things off, I've re-posted few more interesting examples from this blog there (with new accompanying text, mind you). And I've also created few original posts that might be of interest to you: Rye basics: a gentle introduction trough Python examples #1 Rye basics: a gentle introduction trough Python examples #2 Rye basics: a gentle introduction trough Python examples #3 Domain I also bought the domain, which will be the main hub around Rye language: ryelang.org There is not much there yet, just a few lines of Rye that run the webserver. I've never yet tested Rye on a long run...

Interactively displaying Rye values in Console

Still in the theme of blurring the line between programming languages and user interfaces , I improved the display function. It interactively displays Rye values. Enter returns the selected value as you would return it with code, escape returns Void. Blocks, Dicts, Spreadsheets and SpreadsheetRows now work with display . Next I need to make it work with contexts, then adding an option to recursively enter and exit sub-values (I am not sure how I would make that visually yet), add search, select ... This is also a stepping stone towards more interesting and not yet fully developed ideas, so I hope I will work on this more soon. It this sounds interesting you can follow further development on Github or our absolutely new Reddit group !  

Function docstrings, sub-contexts, language as an UI

In the last blog-post I showed a simple utility script that de-duplicates some information. I made a quick interactive solution by using just Rye console to interact with the functionality. I still keep to the idea of language as an user interface , which this simple example was sort of.  For it to be a little better user interface, the ls function mentioned upon entering the console should only display relevant functions, not all Rye's builtin functions. This can be achieved easily with contexts. Normally, when a file evaluates, it's context is the same as the root context of the language. But I now added a --subc flag to Rye executable, which runs code in a sub-context of the root context. So ls just shows what was defined in current code. It also makes sense for ls to show more than just word names, but also descriptions of functions. I added a "docstring" option to Rye function syntax. Both can be seen below. We could very simply create a context for the con...

Simple example of de-duplicating contacts (SQLite)

I must first excuse myself. I haven't been working on Rye for a while. It's not that I forgot about it, far from it, but my regular projects took over for a while. I needed to make major updates at the end of the year at some project, and also re-started a SaaS project for compact support teams that I created in Rebol more than 10 years ago, used ever since, but haven't found time to finalize and offer to others yet. I was also struck a little by ChatGPT demos, and took some time to familiarize myself with GPT, BERT and similar techologies. This was all Python based, so I had no chance to inject it with Rye. This period is unfortunately not over yet, but last week I needed to make a simple script on one of the servers, to de-duplicate some data. Users entered the same contacts multiple times and assigned tasks to them. Script needed to find the duplicates (triplicates, etc.), assign all tasks from the older one to the newer one, and remove the older contact. For the simp...

Advent of Code 2022 - Day 3 - reduce, fold, add-up

This is the Day 3 puzzle for #AoC2022 with Rye. Rye has reduce and fold functions. The difference is, that reduce doesn't accept initial value, so it can be less verbose in some situations, but you need an initial value many times, like when you are adding things up. Initial solution used fold to sum the priorities up, hence it needed initial zero and also an accumulator word (priority, priority1). You don't need to define a word for current value as usually with reduce/fold, because it's injected into code block.     I don't particularly like fold name, because it sounds like CS (computer science) "speak", not something that a person would intuitively name this functionality.  I'm not sure I will find any better name thou, but I thought today it would make sense to make a specialized function for summing/joining things up. That way I can get rid of the initial value (it can be inferred from the type of first returned value) and the accumulator word as...

Advent of Code 2022 - Day 1 & 2 with Rye

Yesterday @pkese and @otobrglez from Twitter made me aware of the Advent of Code 2022 . Oto made his solution in Scala and ZIO and Peter used F#. Both looked cool. I had very little time last two weeks, so almost none for Rye. I was planning for a blogpost about failure handling next.  Well today I couldn't help myself and made a solution for Day 1: "Calorie Counting":     It's really fun, try for yourself: https:// adventofcode.com/2022/day/1   If you just want to watch and compare the languages, there is this reddit megathread for Day 1. I also added my Rye solution :). Update I also solved Day 2. challenge "Rock Paper Scissors". I added two functions to Rye: reverse! and read\lines, others were already there. Star an follow Rye/me on Github .  

A new way to work with Rye - Project local Rye binaries

When you are working on an "wide" project, like a language is, you have to limit your scope somehow. One self-imposed limit for Rye < 1.0 was, that I will not think about modules. Go compiler is known to produce single statically linked binaries. That means that a single file just works , no need for additional installations of any other Go runtime dependencies. This is very nice for distribution. Rye interpreter is also such single binary, and although Go, from version 1.5 supports use of shared libraries, I don't plan to make Rye's bindings dynamic for now. This is a limitation. If you have one global Rye, it has to be compiled in with all the bindings you need on your system. Tags to the go compiler define the modules, so defining them is not hard, but not something you want a Rye programmer to think about. Solving limitations often offers new avenues for innovation. Having a global programming language and global modules is problematic also in dynamic/shared s...

Spreadsheet in action - Transit data demo

I visit news.ycombinator.com - the Hacker News - at least few times a day. It often features interesting news items and intelligent comments. Last week I found a language comparison post by losvedir . Author thought of an interesting and compact problem around serving merged data from two CSV files over HTTP. Author so far tested idea only with static/compiled programming languages. Since Rye is focused on data/information processing and also on "the backend", this sounded like a perfect job for it. Rye also has this very high-level datatype called Spreadsheet (more about the reasoning in the previous blog-post ). This datatype, with some powerful functions, elegant setup for a HTTP server and easy loading of CSV files made whole Rye code very simple. While Go's solution used 180 lines of code and Rust 200 , Rye (which is a dynamic language) took just 38 lines . The problem Program needs to load two CSV files. First (trips) features 72k lines, second (stop_times) 1....

User interface spectrum and a small Spreadsheet datatype demo

Languages I have been repeating this thought, that programming languages are user interfaces for a while, mostly to myself. To put it better, all programming languages are somewhere on the "user interface spectrum". As you go from the lower to the higher levelness of programming languages their core " audience " and their core vocabulary changes.  Lowest level languages speak to the machine, in the machine language, use machine constructs and machine vocabulary ... think Assembly or C.  Somewhat higher level languages forget about the machine a little and speak the language, use constructs and vocabulary of their abstract computational ideas/models. Think Lisp, Java, even Python. Their model can be based on some academic concept or it can be a more human friendly representation of lower level vocabulary and constructs. Even higher on the spectrum are for example command shells. It's audience is an  admin, a person, a user. It's vocabulary is centered around...

Contrary to Redbol-s, Rye got regular expressions

Regular expressions are a standard feature in most languages these days, but they are somewhat of a no-no in Rebol land. Rebol has this superior, very user friendly parse function and they see Regexp-s as some archaic cryptic syntax that is also much more limited than parse expressions are. And Rebol people are correct, regexps are worse and less powerful - but they can still be very useful and just the right medicine at times. Many times you just need that little cryptic but very terse and still quite standard, once you get the hang of it, regular expression to match, extract or replace some simple part of the text and you just don't want to deal with cleaner and more verbose solutions. Below is a simple demo that for better or worse explores all the valid forms of Rye "sentences" you can make. Using the two Regexp related functions for the canvas.   I haven't posted in a while but I am working on Rye on multiple fronts, just haven't completed it yet. I am wor...

Rebol: making simple dialect using parse (dialect)

The Podcast I was recently a guest on a developer oriented podcast Ogrodje . It's in Slovene language . It was great fun to meet two fellow developers and talk about tech and business. The second part of the podcast was about Rye . Because Rye is based on Rebol and because my projects are in big part made with Rebol, there was a lot of talk about Rebol too. If you understand Slovene, you can listen to this and other episodes here:  https://anchor.fm/ogrodje The Rebol But it's hard to explain or even give a basic feeling about a language, if you can't show the code. Example tells a thousand words - to a programmer. I tried to explain that Rebol is not just a little different Python, Ruby, JavaScript, but a small set of uniform ideas (that have more in common with scheme, forth, logo) and that "we" are still exploring how all we could use, to solve our problems (not my quote, can't find the original - it was cooler). I found the one from Douglas Crockford , t...

Full text search integration - Bleve #2

I continue to integrate Bleve search into Rye. This is a small demo that shows new Bleve functionality and also few interesting features of Rye. Like functions *fix* *private* and *enter-console".  With enter-console you can enter a rye console at any point, to debug, explore or just use it as an interface. Since it's an ordinary function, you can call it inside other functions, callbacks, etc ... Function *private* creates a sub-context (*private\* creates one with a docstring) executes code inside it and returns the result. It can be useful for code organization and better separation of concerns.   Anyhow ... follow us on github .   BTW: Rye and Rebol functions have fixed arity. A function with \ at the end is a convention for the same function without \ AND more. There is 'private { }' and 'private\ "doc" { }', there is "ls" and 'ls\ "prin"' for example.

Making a minimal web-application server #1

I expect a minimal web-application server to do two things: serve semi dynamic html pages provide an API interface to web-based client  Very simple HTTP-based API You can create your API-s in plethora of ways, but I mostly used a very simple strpc "standard" to do my API-s for the last 14 years. It's very easy to create and serve an API on the server side and it's very easy to call such API. Any programming language, or a bash shell can do it without any special libraries. I called it strpc (SoTinyRPC) back then. In short, a HTTP POST request to url like this: www.example.com/API?_r=util&_m=add with url-encoded arguments in a POST payload: a=100&b=11 ... would be an example of strpc call. _r - defines resource _m - defines method _f - (optional) would define response format (json, csv, html, ...) _x - (optional) would define explore mode (api self-documents itself) You can make a strpc call from your shell using Curl command, for example: curl -k \ -u $T...