Lisplog

Blogging in Lisp

Search

Feed Aggregator Page 656

Rendered on Thu, 08 Oct 2020 09:03:24 GMT  newer latest older 

Trouble with text inputs and double update roundtrips

via Elm - Latest posts by @lazurski Tad Lispy on Thu, 08 Oct 2020 08:18:01 GMT

I’ve run into strange behavior of text input elements in combination with “double update” - i.e. process Msg from input, issue a Cmd Msg and update model in the subsequent update, like this:

| user input | -- Msg1 value --> | update (model unchanged yet) | -- Cmd (Msg2 value) --> | update (model changed) |

Following is some background.

In my app I have a complex type representing a document. There are many possible transformations that can be applied to it. For versioning purposes every time any transformation is applied I need to capture and store the current time. I want my type to be opaque and transformations to be atomic. But to get time I need to perform a Time.now task and get another Msg with time. I can’t think about any other way than having two updates for every input event.

I came up with something like this:

apply : (Doc -> Doc) -> Doc -> Task Never Doc
apply transform doc =
    Task.map (\time -> transform { doc | version = time }) Time.now

Now when user types in an input I issue an InputChanged message and in the update I return a Cmd constructed with the above apply function. This works, except when the user types in the middle of the text the cursor jumps to the end of the input. Also undo is not working anymore.

Here is a reduced example: https://ellie-app.com/bbLDGML6PbFa1

In writing this I have two goals:

  1. I suppose I should open an issue somewhere, but I’m not sure where.

    In the elm/virtual-dom, elm/html or somewhere else? Or am I just doing it wrong?

  2. I’d like to find a nice way to structure this flow. Any suggestions?

Call for beta testers of browser extension for better Debug.log output

via Elm - Latest posts by @system system on Thu, 08 Oct 2020 04:27:20 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Zach Beane: Non-symbols as keyword arguments

via Planet Lisp by on Wed, 07 Oct 2020 13:05:25 GMT

Sometimes I like to have a short function call to make a lookup table with arbitrary keys and values. Something like this:

(table "name" "Alice" "age" 42) => #<TABLE ...>

This is easy enough to define like so:

(defun table (&rest keys-and-values)
   ;;; loop over keys and values to construct a table
   ...)

But there’s another option that works:

(defun table (&rest keys-and-values &key &allow-other-keys)
  ...)

This version has the advantage that missing arguments (e.g. (table "name")) are caught at compile-time!

I’ve been using this construct for a few years, but recently found out about 3.5.1.5, which says:

It is not permitted to supply a keyword argument to a function using a name that is not a symbol.

Yikes! That seems simple and straightforward: what I’m doing is not permitted. However! Every implementation I’ve tried (only three, admittedly) actually allows my not-symbol keywords without complaint!

I’m too old to think that “it works everywhere today” means “it will continue to work in SBCL tomorrow”, so I’m trying to figure out where I stand. 3.5.1.5 also says this:

If this situation occurs in a safe call, an error of type program-error must be signaled unless keyword argument checking is suppressed as described in Section 3.4.1.4.1 (Suppressing Keyword Argument Checking); and in an unsafe call the situation has undefined consequences.

So does that mean my code is:

  • a safe call with suppressed keyword argument checking?
  • …and is that good to use now and forever?
  • an unsafe call with undefined consequences?
  • something else?

I know the same effect could be achieved with a compiler macro, but I’d like to know if I can use this simpler option safely.

Can we create Mobile apps in elm?

via Elm - Latest posts by @eimfach Robin G. on Wed, 07 Oct 2020 14:31:04 GMT

Also, there is ionic Framework !

Non-symbols as keyword arguments

via Zach Beane Common Lisp by on Wed, 07 Oct 2020 13:05:25 GMT

Sometimes I like to have a short function call to make a lookup table with arbitrary keys and values. Something like this:

(table "name" "Alice" "age" 42) => #<TABLE ...>

This is easy enough to define like so:

(defun table (&rest keys-and-values)
   ;;; loop over keys and values to construct a table
   ...)

But there’s another option that works:

(defun table (&rest keys-and-values &key &allow-other-keys)
  ...)

This version has the advantage that missing arguments (e.g. (table "name")) are caught at compile-time!

I’ve been using this construct for a few years, but recently found out about 3.5.1.5, which says:

It is not permitted to supply a keyword argument to a function using a name that is not a symbol.

Yikes! That seems simple and straightforward: what I’m doing is not permitted. However! Every implementation I’ve tried (only three, admittedly) actually allows my not-symbol keywords without complaint!

I’m too old to think that “it works everywhere today” means “it will continue to work in SBCL tomorrow”, so I’m trying to figure out where I stand. 3.5.1.5 also says this:

If this situation occurs in a safe call, an error of type program-error must be signaled unless keyword argument checking is suppressed as described in Section 3.4.1.4.1 (Suppressing Keyword Argument Checking); and in an unsafe call the situation has undefined consequences.

So does that mean my code is:

  • a safe call with suppressed keyword argument checking?
  • …and is that good to use now and forever?
  • an unsafe call with undefined consequences?
  • something else?

I know the same effect could be achieved with a compiler macro, but I’d like to know if I can use this simpler option safely.

Can we create Mobile apps in elm?

via Elm - Latest posts by @volesen on Wed, 07 Oct 2020 12:05:03 GMT

Maybe try to look at Revery for ReasonML. It feels a bit like Elm.

Can we create Mobile apps in elm?

via Elm - Latest posts by @Noob_Programmer Noob Programmer on Wed, 07 Oct 2020 09:20:17 GMT

thanks then flutter is the thing i’m looking for.

Need to hire Elm developer

via Elm - Latest posts by @CrewNew Kaspar L. Palgi on Wed, 07 Oct 2020 09:15:47 GMT

Thanks, Slack worked well. Not sure though where to find Eastern European “local functional programming group”

Can we create Mobile apps in elm?

via Elm - Latest posts by @opvasger Asger Nielsen on Wed, 07 Oct 2020 09:06:30 GMT

You can get pretty far with progressive-web-apps, but you’ll have some “wiring” written in Elm. Also, if you have major features that rely on stuff Elm can do on it’s own, it might get hairy if you don’t like JavaScript/TypeScript.

My approach has been:

  1. build the Elm-project, where only the little bit of JavaScript required to initialize the app and setup ports is written
  2. Build typescript-modules for specific features, ensure they have nice autocomplete in VS-Code, and deploy them to NPM for import into the main project.

In my mind, Elm is being really ambitious about what our APIs should look like, and for that reason, we’re taking our sweet time getting support for a lot of stuff. Ports are nice once you get the hang of it :sunny:

Can we create Mobile apps in elm?

via Elm - Latest posts by @francescortiz Francesc Ortiz on Wed, 07 Oct 2020 08:49:04 GMT

IMHO, go for flutter. I have done native development for both android and ios, react native and qt.

  • Native development makes you do all the work twice
  • In react native you suffer from not having a clear and common way of doing things and depending on the community for almost everything. It follows the javascript ecosystem norm: many projects doing the same thing with slight improvements instead of one big good thing.
  • Qt is almost impossible to compile to mobile and has a very tiny community, though QML is a really great idea.

Flutter does the things they way they need to be done:

  • Compiles to native binaries like Qt.
  • Has a shared repository for packages from the community like typescriptwith npmjs.
  • Has officially supported UI for both android and ios like native development.
  • It is supported by a big company, Google, the same as react, Facebook.

But also, it adds:

  • You code with Dart, kind of like javascript, but with some improvements to make writing code easier (less error prone).
  • It offers clearly differented UI libraries for ios and android. When you start coding a mobile app, it is common to try to have the same UI codebase for both ios and android, but at some point it becomes unmaintainable and then you have to split the two UIs codebases. Flutter takes you to the right direction from the beginning.
  • It uses declarative UI, so it feels familiar if you come from Elm.

More or less this is my experience.

Elm in a nutshell

via Elm - Latest posts by @system system on Wed, 07 Oct 2020 07:56:25 GMT

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.

Can we create Mobile apps in elm?

via Elm - Latest posts by @stevenyap Steven Yap on Wed, 07 Oct 2020 05:48:12 GMT

We have done an Elm website and wrap it in a WebView within mobile app.
We use native code in Swift/Java to link up the WebView (vs ports) and mobile.

If your mobile app does not rely heavily on native functionalities such as GPS, bluetooth, etc AND don’t have heavy animation,
this setup is good enough to work with.

Otherwise, a typescript-React Native approach is the next best thing we have…
It’s not even close to the joy of coding in Elm
but it is the next best thing… :upside_down_face:

Can we create Mobile apps in elm?

via Elm - Latest posts by @Noob_Programmer Noob Programmer on Wed, 07 Oct 2020 04:58:00 GMT

Im about to start a startup , so we want to build mobile apps that’s our targeted audience .
So heres the thing i dont like JS and especially react.js and flutter is some bunch of widgets . So im wondering can we make our front end of our mobile apps in elm i dont know much about front end .
any advice would be greatful.

Need to hire Elm developer

via Elm - Latest posts by @mattpiz Matthieu Pizenberg on Tue, 06 Oct 2020 16:44:39 GMT

There is also a #jobs channel on the elm slack. I think some newsletters used to relay job offers, I don’t know if they still do. And you might also want to check your local functional programming groups where there might be places to post jobs ads.

Need to hire Elm developer

via Elm - Latest posts by @CrewNew Kaspar L. Palgi on Tue, 06 Oct 2020 10:50:47 GMT

Hey guys! Hope it’s allowed to post here but as it’s pretty hard to find Elm devs in other usual freelance sites from where we have got all the great Vue/Rect devs then trying here. Pls email me kaspar@crewnew.com if you’re Elm dev and want to work with cool startup built in Elm and Node. Thanks.

[off my chest] omg elm is so fun

via Elm - Latest posts by @pdamoc Peter Damoc on Tue, 06 Oct 2020 03:51:13 GMT

You don’t have to love JS. Just let it be what it is.

New Elm Language Server and VS Code plugin versions

via Elm - Latest posts by @opvasger Asger Nielsen on Tue, 06 Oct 2020 02:04:20 GMT

Amazing work :heart::v::pray: Thank you so much

Alexander Artemenko: trivial-thumbnail

via Planet Lisp by on Mon, 05 Oct 2020 22:19:55 GMT

This is the library by @Shinmera. It does one trivial thing - shrinks images, squeezes them into smaller thumbnails. Actually, it is a wrapper around ImageMagick.

The cool thing about this library is that it is able to preserve GIF animations. This way you can create animated avatars for users of your next-generation Facebook killer social network, written in Common Lisp!

For example, let's pretend the user loads this cute dog animation which has 800×800 pixels size, and weights 44KB:

If we want our avatars to be 64x64 pixels, then trivial-thumbnail will help us:

POFTHEDAY> (trivial-thumbnail:create "docs/media/0200/dog.gif"
                                     "docs/media/0200/small-dog.gif"
                                     :width 64)
#P"docs/media/0200/small-dog.gif"

Here is the result:

To make it work you have to install ImageMagick. On OSX the easiest way to do this is to use Homebrew:

brew install imagemagick

There are also other options. They are covered by documentation.

Seems this is a cool library to make avatars, preview and thumbnails.

New Elm Language Server and VS Code plugin versions

via Elm - Latest posts by @razze Kolja Lampe on Mon, 05 Oct 2020 22:52:57 GMT


New Elm Language Server and VS Code plugin versions

via Elm - Latest posts by @jmbockhorst Jon Bockhorst on Mon, 05 Oct 2020 22:35:46 GMT

We have released a new version of the Elm Language Server! (v1.12.0 of the server, v1.4.0 of the VS Code client)

The biggest feature of this release was the implementation of the type inference system, which enables the ability add missing type annotations for functions, create missing function declarations from usage, and enable completions in places that were not previously possible. It will also enable more cool features in the future releases. This was a big effort (~7,000 lines of code added), but we did thorough testing and hope that it works well for you. Big thanks to the team from intellij-elm, as their type inference algorithm inspired us to bring it to the language server.

Another nice feature is you can now specify Main.elm entrypoints via elm-tooling.json. See https://github.com/elm-tooling/elm-language-server#configuration for more on how to configure it.

Something else to note is that elm-analyse is now disabled by default. In upcoming releases we will be replacing elm-analyse functionality with a native implementation, hopefully for a better overall experience.

Here is the full changelog:

  • Added type inference
  • Added type inference diagnostics for missing top level type annotations
  • Added codeActions to infer annotations for functions
  • Make entrypoints configurable via elm-tooling.json
  • Create function declaration from usage
  • Added goto definition and references for ports
  • Tree sitter now parses the files incrementally after the initial scan
  • More goto definition improvements
  • Default elmAnalyseTrigger to never

We had contributions from @razze, @lydell, and myself this iteration.

If you find any bugs or have ideas for new features, feel free as always to create an issue on GitHub.

VS Code client: https://marketplace.visualstudio.com/items?itemName=Elmtooling.elm-ls-vscode

 newer latest older