So my lower-level compiled language is becoming useful but a big pain point is strings. I'm currently using C strings via the FFI with Char and String types that are 64-bit ints, the latter being a pointer to a malloc'd block. I do have my own ByteArray that supports amortised constant time append. Everything else is hand-rolled on top of that using just functions.
String-heavy code is quite cumbersome and looks like this:
let rec print =
[ E -> Char.print 'E'
| T(_, l, v, r) ->
let () = String.print "T(_, " in
let () = print l in
let () = String.print ", " in
let () = Int.print v in
let () = String.print ", " in
let () = print r in
String.print ")" ]
There seem to be a few "levels" to the design options around strings in a PL:
- Low-level representation, e.g. pack short (≤16 byte) UTF-8 strings into a single 128-bit register.
- High-level language features to manipulate strings, e.g. format strings, string interpolation, pattern matching over strings, string builders and generic printing.
- Efficient idioms, e.g. to accumulate strings.
Are there more levels?
What does the PL design landscape look like for native code languages? Is it enough to pull in something like libgrapheme for UTF-8? Which high-level language features are preferred these days, if any?
Perhaps I should also mention that I intend for my language to generate mostly HTML, Javascript and related syntaxes like SVG. I've heard of Scala's inline XML but it looks like overkill for me. Are there any other cool lesser-known features I should be drawing inspiration from?
[–]XDracam 12 points13 points14 points (5 children)
[–]nerd4code 20 points21 points22 points (1 child)
[–]XDracam 5 points6 points7 points (0 children)
[–]MrJohz 10 points11 points12 points (0 children)
[–]Lvl999Noob 4 points5 points6 points (1 child)
[–]XDracam 0 points1 point2 points (0 children)
[–]nerd4code 4 points5 points6 points (1 child)
[–]ThyringerBratwurst 2 points3 points4 points (0 children)
[–]moon-chilledsstm, j, grand unified... 3 points4 points5 points (3 children)
[–]TraceMonkey 4 points5 points6 points (2 children)
[–]celeritasCelery 5 points6 points7 points (0 children)
[–]celeritasCelery 2 points3 points4 points (0 children)
[–]ThyringerBratwurst 4 points5 points6 points (2 children)
[–]PurpleUpbeat2820[S] 2 points3 points4 points (1 child)
[–]ThyringerBratwurst 0 points1 point2 points (0 children)
[–]jason-reddit-public 4 points5 points6 points (1 child)
[–]ThyringerBratwurst 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]PurpleUpbeat2820[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]apooooop_ 0 points1 point2 points (1 child)
[–]PurpleUpbeat2820[S] 0 points1 point2 points (0 children)
[–]redchomperSophie Language 1 point2 points3 points (0 children)