Kho tháng 10/2019

Thứ ba, 22 Tháng 10 năm 2019 20:09:26 ICT

Oh oh Close Combat Specialists

EXALT "king of the hill" mission. Put one CCS Assault near the encoder. Then watch EXALT dash mindlessly to the encoder and get shot down one by one. Like moths to the flame.


Cập nhật 1 lần. Lần cuối: Fri Aug 26 00:20:24+0003 2022

Tác giả: pclouds | Liên kết tĩnh | Game

Thứ sáu, 18 Tháng 10 năm 2019 19:29:45 ICT

emscripten on Gentoo

grr grr GRRR. Install clang, lld and nodejs (optionally openjdk-bin?). Stick to e6e3d7dbc (Prepare for mainReadsParams flag in wasm-emscripten-finalize metadata (#9045), 2019-07-22) but with one more change.

diff --git a/tools/shared.py b/tools/shared.py
index 65fcdac02..1bba1dbaa 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -398,7 +398,7 @@ actual_clang_version = None
 
 def expected_llvm_version():
   if get_llvm_target() == WASM_TARGET:
-    return "10.0"
+    return "9.0"
   else:
     return "6.0"
 

Then build with

./emcc hello.c -o hello.html

and launch the web server

./emrun --no_browser --port 8080 hello.html

It's a lot of work. But hopefully it works? Maybe try again with 1.38.38 cherry picking one change to accept that mainReadsParams metadata.

Next step, compiling Gauche. It's going to be a nightmare...


Tác giả: pclouds | Liên kết tĩnh

Thứ năm, 17 Tháng 10 năm 2019 20:01:14 ICT

$LANG affects fc-match! This explains EVERYTHING.

Fixed with

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <match target="pattern">
    <test name="lang" compare="contains">
      <string>vi</string>
    </test>
    <test name="family">
      <string>sans-serif</string>
    </test>
    <edit name="family" mode="prepend" binding="strong">
      <string>Droid Sans</string>
    </edit>
  </match>
</fontconfig>

Cập nhật 1 lần. Lần cuối: Sat Oct 19 00:42:10+0011 2019

Tác giả: pclouds | Liên kết tĩnh | Linux

Thứ ba, 15 Tháng 10 năm 2019 20:25:11 ICT

Good bye dev-lang/ruby. So long, but I can't keep up anymore.


Tác giả: pclouds | Liên kết tĩnh

Thứ ba, 15 Tháng 10 năm 2019 19:32:57 ICT

Gentoo is really high maintenance, especially no maint for over a year...


Tác giả: pclouds | Liên kết tĩnh

Chủ nhật, 13 Tháng 10 năm 2019 10:33:02 ICT

Reading define-environment-monad macro

This probably shows how strange pattern-matching programming is. Let's start at the top:

(define-syntax define-environment-monad
  (syntax-rules ()
    ((define-environment-monad name clauses ...)
     (dem name (ask %ask) (tell %tell) c f! f s r w u z () clauses ...))))

Standard stuff. The macro takes a name and a list of clauses and expands it to "dem". All those short parameters should have better names (copy, fork, sequence, run, with, update and return respectively) but we'll soon see why they are this short.

So let's look at dem macro, the first part is pretty simple still

(define-syntax dem
  (syntax-rules (fields: sequence: bind: bind-fork:
                 local: local!: run: return: ask: tell: copy:)
    ((dem n ask tell c f! f s r w u z (fls ...)
          (fields: (fl get put) . fl-r) . x)
     (dem n ask tell c f! f s r w u z (fls ... (fl #f get put))
          (fields: . fl-r) . x))

Recursive expansion here we go. Remember the () parameter after z? What we do here is to move all the (fields: (fl get put)) clauses into this list, each list item consists of the field name fl, default value #f and the setter put and getter get.

If your original define-environment-monad only contains (fields: ...) clauses after name, we're almost done here. We just need the termination rule to prevent infinite recursive expansion.

((dem n ask tell c f! f s r w u z (fls ...) (fields:) . x)
 (dem n ask tell c f! f s r w u z (fls ...) . x))
((dem n ask tell c f! f s r w u z ())
 (syntax-error "missing fields clause in define-state-monad"))

But the macro can handle more so let's continue.

((dem n ask tell c f! f s r w u z fls (bind: fn!) . x)
 (dem n ask tell c fn! f s r w u z fls . x))

If you really pay attention, you can see that f! is now replaced with fn! from (bind: fn!) so we give the bind function f! a real name, instead of some internally generated name to keep hygiene.

This pattern repeats for all other clauses...

((dem n ask tell c f! f s r w u z fls (bind-fork: fn) . x)
 (dem n ask tell c f! fn s r w u z fls . x))
((dem n ask tell c f! f s r w u z fls (sequence: seq) . x)
 (dem n ask tell c f! f seq r w u z fls . x))
((dem n ask tell c f! f s r w u z fls (run: run) . x)
 (dem n ask tell c f! f s run w u z fls . x))
((dem n ask tell c f! f s r w u z fls (return: return) . x)
 (dem n ask tell c f! f s r w u return fls . x))
((dem n ask tell c f! f s r w u z fls (local: local) . x)
 (dem n ask tell c f! f s r local u z fls . x))
((dem n ask tell c f! f s r w u z fls (local!: local!) . x)
 (dem n ask tell c f! f s r w local! z fls . x))
((dem n ask tell c f! f s r w u z fls (ask: a %a) . x)
 (dem n (a %a) tell c f! f s r w u z fls . x))
((dem n ask tell c f! f s r w u z fls (tell: t %t) . x)
 (dem n ask (t %t) c f! f s r w u z fls . x))
((dem n ask tell c f! f s r w u z fls (copy: copy) . x)
 (dem n ask tell copy f! f s r w u z fls . x))
((dem n ask tell c f! f s r w u z fls clause . x)
 (syntax-error "unknown clause" 'clause))

The short names here kinda help, once you get over the shock because it's a bit easier to spot the expansion, which has more than one letter.

The last part of dem is standard (and for real) macro expansion, not much to talk about...

((dem n (ask %ask) (tell %tell) c f! f s r w u z ((field init get put) ...))
 (begin
   ;; Internals
   (define-record-type n
     (make-state field ... %props)
     state?
     (field get put) ...
     (%props get-props set-props!))
   (define (%ask st x)
     (case x
       ((field) (get st)) ...
       (else (cond ((assq x (get-props st)) => cdr) (else #f)))))

except one last thing. When define-syntax is used inside define-syntax, you can't simply use ... in the inner defintion because it's interpreted as ... of the outer one. So you need to give a different name for the ellipsis syntax, in this case ooo.

(define-syntax f!
  (syntax-rules ooo ()
    ((f! ("step") (params ooo) ((p param) . rest) . body)
     (f! ("step") (params ooo (p param)) rest . body))
    ((f! ("step") (params ooo) ((param) . rest) . body)
     (f! ("step") (params ooo (param param)) rest . body))
    ((f! ("step") (params ooo) (param . rest) . body)
     (f! ("step") (params ooo (param param)) rest . body))
    ((f! ("step") ((p param) ooo) () . body)
     (lambda (st)
       (let ((p (ask st 'param)) ooo)
         ((let () . body) st))))
    ((f! params . body)
     (f! ("step") () params . body))))

which is the same as this when not nested in another define-syntax

(define-syntax f!
  (syntax-rules ()
    ((f! ("step") (params ...) ((p param) . rest) . body)
     (f! ("step") (params ... (p param)) rest . body))
    ((f! ("step") (params ...) ((param) . rest) . body)
     (f! ("step") (params ... (param param)) rest . body))
    ((f! ("step") (params ...) (param . rest) . body)
     (f! ("step") (params ... (param param)) rest . body))
    ((f! ("step") ((p param) ...) () . body)
     (lambda (st)
       (let ((p (ask st 'param)) ...)
         ((let () . body) st))))
    ((f! params . body)
     (f! ("step") () params . body))))

It's not something I want to read everyday to be honest. This macro is also interesting because it converts the params list of parameter names to variable bindings for let form. For example if you write

(f! (abc def) #f)

then you get

(lambda (st)
  (let ((abc (ask st 'abc))
        (def (ask st 'def)))
    #f))

Quite handy to know. There's also creative use of ellipsis...

((dem n (ask %ask) (tell %tell) c f! f s r w u z ((field init get put) ...))
 ....
 (define (%ask st x)
   (case x
     ((field) (get st)) ...
     (else (cond ((assq x (get-props st)) => cdr) (else #f)))))

Here we generate the whole case block using the defintions from the dem macro, so if you have

(dem .... z ((abc #f get-abc set-abc!) (def #f get-def set-def!)))

then the case block becomes

(case x
  ((abc) (get-abc st))
  ((def) (get-def st))
  (else ...

Tác giả: pclouds | Liên kết tĩnh | Scheme