Preskoči na glavno vsebino

Objave

Prikaz objav, dodanih na december, 2020

Towards Rye's minimal web-application library #3

Ok, so I added support for sessions to http integration. It's based on very solid Go's gorilla/sessions . With it I made a simple login functionality and some typical functions you would need to provide a simple API for a browser based web-application. The five functions of "web framework" remained the same as in the first post . The Account-resource has many more methods now:   The page resource now has 3 more methods that require that the user is logined and that the page it sets or deletes is owned by that user. If you want to delete a page and aren't logined, you get 401 status, if the page doesn't exist or isn't yours you get 403 - forbidden status and if the page is your you get status 200 and a number of affected pages back. You can see the full code on github repository under examples/webapp_3. You need to compile Rye with psql and sqlite support. Next I need to make validation failure return as JSON response to the client and make the signup f

New wip concept: skipping words

My (fb) posts about Rye-s failure handling have been somewhat controversial so far. Remember that I am just experimenting here. I know known solutions exist and I see no problem in implementing them in Rye if these experiments fail to produce a value. So far I am following the path and crossing the bridges that show-up before me ...   The return words, especially connected to handling of failures like ^fix and ^check had a side effect of flattening the code, which made the code visually and conceptually simpler. Return words work on the level of functions. They provide an escape hatch out of whole function. But inside a local stream of pipe and op-words we don't have such an escape hatch. So we need to sometimes resort to code nesting sooner than we would want to. I was looking at this example of Maybe monad in Ruby (using ruby-possibly library). If I try to recreate this in Rye the word fix comes to mind. Rye has no null type so far and liberally uses failures where some ot

Towards Rye's minimal web-application library #2

This is a continuation from the previous post . I integrated the postgresql into Rye, and made it work with the same SQL dialect that the SQLite integration uses. The "web framework" code (5 functions) is the same as in the previous post. The web-application and server code is below. A couple of notes ... The SQL dialect is in short a dialect of Rye values (not a string) that produces prepared SQL statements avoiding the usual bug-prone positional arguments. Open, query and exec are generic methods and dispatch on the kind of the first argument (in this case a postgresql database). SQLite also uses these generic words, so do other also non-database kinds. Query returns value of type Spreadsheet . It's similar to your Excel spreadsheet or in more technical terms like R-s frame. Some spreadsheet specific functions are sum, avg, max, min, and also two to quickly retrieve a value of the first and second cell like A1 and B1 ... that correlates to columns A and B in

Rye in webassembly (WASM)

Go-lang can also compile to webassembly (WASM). I was trying to make Rye compile to WASM with TinyGo for a while and this weekend I managed to produce a build. TinyGo is an alternative compiler that uses LLVM and should produce much smaller wasm packages. The compilation passed but I wasn't able to make the full interpreter work in a browser.  I could be wrong but it seems that a PEG parser library that I am using drastically increases the .wasm size (to 6MB) and compilation time to more than 45 minutes. I could be wrong. I will explore this option later but I decided not to take many more 45 minute tries. Consequent compilations can be much much faster, but if I remove and add the dependency it seems I am back to 40 minutes gone. Another option would be to rewrite a loader in a simpler PEG parser generator (not a "library"), but not this weekend. So I tried the native Go WASM compilation and .wasm in my case was "just" 3MB (without the PEG parser