2

Web app on AWS Lambda with Janet

 2 years ago
source link: http://thegeez.net/2021/10/28/janet_web_app_aws_lambda.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Web app on AWS Lambda with Janet

28 Oct 2021

Janet is a small functional and imperative programming language. The language has some similarities to Clojure with its Lispy syntax, its data notation, and with its proper REPL for dynamic developing within a running system. Janet also compiles its runtime and VM to C and can therefore run almost anywhere.

All of Janet's features make it a good candidate to make AWS Lambda serverless functions with. This is because Janet programs start up and compile quickly, certainly when compared to a combination of Clojure and native-image compilation. Postings is a simple forum web app on AWS Lambda behind an API Gateway and using DynamoDB as the database.

Postings web app at https://iakerss4c6.execute-api.eu-central-1.amazonaws.com, source at https://github.com/thegeez/janet-postings

Differences between Janet & Clojure

Janet and Clojure look alike and share many concepts and programming approaches. This is usefull to get started quickly, but can also trip you up when things that look the same in both languages behave slightly different. Here are some of the things I ran into:

  • Immutable and mutable data - Janet has immutable data for values, but for data that will change over time you'll need to use the mutable variants.
    {:struct "immutable data"} # an immutable struct
    # Can't create another immutable datastructure through 'assoc' or 'conj' from a struct, need to use a table:
    (def table @{:mutable "data"})
    (put table :extra-key "value")
    table #=> @{:mutable "data :extra-key "value"}
    
  • Data and value equality - Immutable data has value equality semantics, the mutable data structures do not.
    (= {:a 1} {:a 1}) #=> true, immutable structs are equal
    (= @{:a 1} @{:a 1}) #=> false (!!), mutable tables are not equal
    (deep= @{:a 1} @{:a 1}) #=> true, can check mutable data structures for equality with deep=
    
  • nil punning - If a construct in Janet expects a data structure you can't pass nil to it instead of an empty collection. (This is the thing from Clojure that trips me up most often in Janet.)
    (loop [number :in [1 2 3]] ...do something with number...)
    (loop [number :in nil] ...collection is empty...) #=> error: expected iterable type, got nil
    
  • Dynamic development with the REPL - Janet uses early binding. So if you recompile a function in the REPL, any function that uses the recompiled function will not use the newest definition. This is usually not what you want. To get the late binding that Clojure uses, redefine "defn" to "varfn" during development. For other dynamic behaviors the environment in Janet is first-class and inspectable and changeable through "(curenv)".

The source for the Posting app is here: https://github.com/thegeez/janet-postings


Recommend

  • 7
    • www.tuicool.com 5 years ago
    • Cache

    Janet 0.5.0

    Medium-sized update, with a number of improvements including dynamic scoping and some more debugging facilities. From the changelog: Fix some bugs with buffers. Add trace and...

  • 20

    Impressive title right? The following image is a "sneak peek" at the full implementation and the resultant system: To see it co...

  • 22
    • Github github.com 4 years ago
    • Cache

    A janet web framework

    You Found Joy! Joy is a full stack web framework written in janet (use joy) (defn home [request] (render :text "You found joy!")) (defroutes rou...

  • 8
    • www.trustnodes.com 3 years ago
    • Cache

    Janet Yellen Accused of Banking Corruption

    Janet Yellen Accused of Banking Corruption – TrustnodesThe US Treasury Secretary Janet Yellen has been accused of corruption due to receiving $7.2 million in ‘speaking fees’ from just Citi bank and the Citadel hedge fund. ...

  • 5
    • pan.earth 3 years ago
    • Cache

    Why I will stay Janet

    This post is the last part of my Óde to Janet programming language. If this is the first time you are here, please read the past and

  • 1

    Using AWS Lambda to Reduce NodeJS App SizeSeptember 13th 2021 new story8 This article highlights...

  • 7
    • ianthehenry.com 2 years ago
    • Cache

    Making a Game in Janet

    October 7, 2021 Making a Game in Janet, Part 2: Judging Janet In order to continue making progress with my little Janet game, I had to write some tes...

  • 6

    Serverless search on AWS Lambda with Janet and SQLite11 Jan 2022 Recently I have been porting a simple app on AWS Lambda for posts and comments to use the Janet programming language. A

  • 2

    Serverless Clojure web app on AWS Lambda07 Apr 2020 The Postings app is a simple web application for posting text and comments. It is very old fashioned because it serves html pag...

  • 4

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK