ArneBab, (edited ) German
@ArneBab@rollenspiel.social avatar

define-typed: a static type syntax-rules macro for #Guile to create API contracts and help the JIT compiler create more optimized code:

https://www.draketo.de/software/guile-snippets#define-typed

Improved thanks to feedback from Vivien and Zelphir in the Guile User mailing list.

Just 26 lines to get argument and return value typing without changing Guile.

I love the flexibility of #Scheme ❤️

#freesoftware #gnu #programming #coding #code

ramin_hal9001,
@ramin_hal9001@emacs.ch avatar

@ArneBab this is awesome! I want to explore this type system a bit myself!

ArneBab,
@ArneBab@rollenspiel.social avatar

@ramin_hal9001 Don’t raise your expectations too much: it’s just simple syntactic sugar for runtime checking!

ArneBab,
@ArneBab@rollenspiel.social avatar

@ramin_hal9001 (though I realized 5 minutes ago that it is actually easy to use this to provide type information to the editor by simply recording the type-checking procedures in the procedure-properties, so we could at least have as-you-type validation whether the values match the required values)

ramin_hal9001,
@ramin_hal9001@emacs.ch avatar

@ArneBab I have been playing around with monadic code in Guile myself lately, and I can see a fairly easy way to incorporate type checking into my system as well, and you have already given me some ideas here.

What is nice is that if you make use of record types as a kind of Functor, and all of your monadic code constructs functors, and the compiler does constant folding and dead code elimination passes, the optimizer would probably be able to tell right away any time you use a procedure wrapped in the Functor type that a "cond" or "case" expression will always evaluate only along a single branch. So it should be able to eliminate code branches that cannot pass type checking.

But I have more experimentation to do before I can confirm whether this is the case. Also, I don't think those optimizations can apply everywhere, only at top-level declarations. But I could be wrong, it might work in arbitrarily nested closures as well.

ArneBab,
@ArneBab@rollenspiel.social avatar

@ramin_hal9001 Keep in mind to check the ,disassemble along the way to ensure that what you expect actually happens.

For some hints, see https://dthompson.us/posts/optimizing-guile-scheme.html

(and where it does not, maybe send a patch if it seems beneficial in general?)

ramin_hal9001,
@ramin_hal9001@emacs.ch avatar

@ArneBab that is precisely what I intend to do. Thanks for that link to David Thompson's article, I don't think I had seen that one before.

ArneBab,
@ArneBab@rollenspiel.social avatar

@ramin_hal9001 that article is what prompted me to finally do the typing experiment in the first place ☺

(it’s great!)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • anitta
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • provamag3
  • tester
  • Leos
  • megavids
  • JUstTest
  • All magazines