Petite Chez Schemeãã¤ã³ã¹ãã¼ã«
tar -xzvf pcsv8.4-ti3osx.tar.gz cd csv8.4/costom ./configure --installprefix=~/local --installman=~/local/share/man make make install
ãã㨠petite 㨠scheme-script ãã¤ã³ã¹ãã¼ã«ããããroot権éã«chownãããã¨ããããã¦ããããã¨ã©ã¼ãåºããã¨ããããç¡è¦ãããããã¨ã
$ petite cannot find compatible petite.boot in search path "/Users/kaki/lib/csv%v/%m:/usr/lib/csv%v/%m:/usr/local/lib/csv%v/%m"
ã¨è¨ããããbootãã¹ãééã£ã¦ããã®ã§
petite -b ~/local/lib/csv8.4/ta6osx/petite.boot
ã§èµ·åã§ãããããã§
cd ~/local/bin mv petite petite8.4
petite
#!/bin/sh exec petite8.4 -b ~/local/lib/csv8.4/ti3osx/petite.boot "$@"
petite-script
#!/bin/sh exec petite8.4 -b ~/local/lib/csv8.4/ti3osx/scheme-script.boot --script "$@"
ã¨ãã¦ã¿ããscheme-script ãããªãããã ãã©ã¨ããããä¿çã
><>(Fish)ã«å ¥éãã
ãããã
><>ã¨ããé£è§£ããã°ã©ãã³ã°è¨èªã某ゴルフ場ã«å ¥ã£ãã®ã§ãå ¥éãããè¨èªã®ååä¸ãã°ã°ã©ããªãã£ãé常ã«ä½ãæ¥æ¬èªã®æ å ±ãè¦å½ãããªãã£ãã®ã§ãããã«æ¥æ¬èªã§èªåã®><>å ¥éã¸ã®éä¸ãè¨ããããã¾ã§åå¿è ã調ã¹ãªããæ¸ããæç« ãªã®ã§ãééããå¤åã«å«ã¾ãã¦ããå¯è½æ§ããããééããè¦ä»ãããæãã¦ã»ããã
(ãã®æç« ã¯ãBefungerè¦ç¹ã§æ¸ããã¦ãããåæç¥èã¨ãã¦ã(æã´ã«ãå ´ã®å¤å°ã«ã¹ã¿ãã¤ãºããã)Befungeã®ç解ãè¦æ±ãããããããªãã)
ä»»æã®åã®å¼æ°ãç¡éã«æ¶è²»ããç©ºè ¹é¢æ°ã¯Haskell(GHC)ã§ã¯æ¸ããªãã®ãï¼
Schemeã§ããã¨
(define (hungry x) hungry)
ã¿ãããªãã¤ã
ããã¾ã§ã¯ã§ãããåè: https://github.com/jstolarek/sandbox/blob/master/haskell/Hungry.hs
Prelude> :set -XRankNTypes Prelude> data Hungry = Hungry { (%) :: forall b. b -> Hungry } Prelude> let fix f = f $ fix f Prelude> let hungry = fix id :: Hungry Prelude> :t hungry % 42 % 'c' % [] hungry % 42 % 'c' % [] :: Hungry
unHungry (ä¸ã§ã¯ (%)
) ç¡ãã§ã¯æ¸ããªãã®ããªãã
(è¿½è¨ 18:38)
ã§ãããã®ãï¼
åèï¼可変長引数をHaskellで。 - ここにタイトルを入力|
Prelude> class Hungry f where hungry :: a -> f Prelude> instance Hungry a => Hungry (f -> a) where hungry _ = hungry Prelude> :t hungry 42 'c' [] hungry 42 'c' [] :: Hungry t => t
åã¯ã©ã¹ã«ããã¨ããã£ã½ããã®ãä½æ ãã§ãããä½æ ã ï¼
ã¯ããã¦ã®Quineãªã¬ã¼
æ¦è¦
æ¨æ¥ãèªåèªèº«ãåºåããHaskellããã°ã©ã ãçæããOCamlããã°ã©ã ãçæããSchemeããã°ã©ã ãçæããRubyããã°ã©ã ãçæããJavaScriptããã°ã©ã ãçæããCããã°ã©ã ãæ¸ããã
#include<stdio.h> int main(){char*g="var p=print;p('puts %%^(format #t!Printf.printf~s~s!(x->string`main=putStr%%S)^.tr *?!...?#;p <<_;$><<?)');p('#include<stdio.h>');print(%cint main(){char*g=%c%s%c;printf(g,47,34,g,34,47);}%c.source);p('_')";printf(g,47,34,g,34,47);}
以ä¸ã®ããã«åä½ãããMakefileã¯å¾è¿°ã
$ make diff clang -std=c99 -Wall -W -Werror -pedantic -o quine-relay-c start.c && ./quine-relay-c > quine-relay.js v8 --use_strict quine-relay.js > quine-relay.rb ruby quine-relay.rb > quine-relay.scm gosh quine-relay.scm > quine-relay.ml ocaml quine-relay.ml > quine-relay.hs runghc quine-relay.hs > goal.c diff -u start.c goal.c $ wc start.c quine-relay.* 2 9 270 start.c 0 8 287 quine-relay.hs 0 13 402 quine-relay.js 0 8 304 quine-relay.ml 4 15 360 quine-relay.rb 2 11 333 quine-relay.scm 8 64 1956 total
åæ©
ãSchemeãRubyãå¾æã§HaskellãOCamlãæ¸ãã¾ãï¼ãã¨å ã ã¨è¨ããããã«ãªãããããªãã°ãããã®è¨èªã§Quineãªã¬ã¼ãããããæãä»ãã¦ãã¾ã£ãããã«ã¯ãæ¸ããã°ãªãã¾ããããæã£ã¦ããææããã£ãã
ãã®ããã«æ±ºå¿ãã¦æ¸ãå§ããã®ã ããåå¤ã«é£ããã¯ãªãããã®æ¥ã®ãã¡ã«ã§ãã¦ãã¾ã£ãã
æ§æ³
ã³ã³ã»ãããQuineãªã¬ã¼èªä½ã¯偉大なる先人ãåãã®ãæãéãã¦ããã£ãããããèªåã¯Quineãªã¬ã¼ã«ã¯åææ¦ãªã®ã§ãä»åã¯å¾æè¨èªã®ã¢ããã«ã«éç¹ãç½®ãã¦ãã¨ããããé«ç´è¨èªæ°åã§ã®å®æãç®æããã¨ã«ããã次ã«é åºãåé¡ã¨ãªããBrainf**kãBefungeãå
¥ããã§ããªãã®ã«é åºãä»»æã§ã¯è¶£ã«æ¬ ããã¨ãããã®ãããã¯ãªãã¨ãªãCãèµ·ç¹ã«ãã¦è§¦ã£ãé ã«ãããçµæãèªåã®ããã°ã©ãã³ã°ã®å¦ã³ã®æ´å²ã辿ãæå¾ã¯åå¿ã«å¸°ãã¨ããå人çã«æ°æã¡æªã大層趣ã®ããããã°ã©ã ãã§ãããã£ãããã¨ãä»åã®ä¸»æ¨ã«éã¿ã¦ãç¹å®ã®è¨èªã§ä½éã«ãã¨ã¹ã±ã¼ããã¦æ®ãã®è¨èªã¯æååãåºåããã ããã¿ãããªããã§ã¦ãªãã¨ã¯ãªãã¹ãããªãããã«ããã
ããä¸ã¤ã追å ã®å¶ç´ã¨ãã¦Cã³ã³ãã¤ã©ã®ãªãã·ã§ã³ã« -std=c99 -Wall -W -Werror -pedantic
ãä»ãããã¨ã«ãããããã§ãã®ããã°ã©ã ãã³ã³ãã¤ã©ãé»ãç¨ã®çã£å½ãªããã°ã©ã ã§ãããã¨ã¯ç¢ºå®çã«æãããå¥å¦ãªæåãæ¡å¼µã«ä¾åãã¦ããããã³ã³ãã¤ã©ã«ãã£ã¦ãã©ãã©ã«å¼ãè£ããããã¨ã«ãªãã
ã¤ãã§ã«ã¡ãã£ã¨ç¸®ããã
ææ³
- é£ããã¨ããããé¢åèã
- æ¹è¡ã®ããã«\nãæ¸ãã¨ããã¯ã¹ã©ãã·ã¥ã§é¢åãå¢ããã®ã§JSã®printãæ´»ç¨
- JSãªãæ£è¦è¡¨ç¾ãªãã©ã«ã使ããâæ£è¦è¡¨ç¾ãªãã©ã«å ã§ã¯æ¬å¼§ã®å¯¾å¿ããã¡ã¿æåãåæ³ãããªãã¨ã ãâã¨ã¹ã±ã¼ãã®ããã«ããã¯ã¹ã©ãã·ã¥ãå ¥ããã¨é¢åãå¢ããâãããä¸æ
- ããã¯ã¹ã©ãã·ã¥ã¯æé¤
- å¤æ§ãªãªãã©ã«ãããè¨èªã¯ããããæå¼·ã
- rawæååãªãã©ã«ãããè¨èªã¯æå¤ã¨å°ãªããã©ãããã¨ãããªã
- è¤æ°è¡ã®æååãªãã©ã«ãæ¸ããªãè¨èªã¯(çç¥ããã¾ãã)
- ã¿ããª
printf
ã®ãã¨ã好ããªãã ãªã( ꒪⌓꒪)
ä»é²
.PHONY: all clean diff CC = clang CFLAGS = -std=c99 -Wall -W -Werror -pedantic JavaScript = v8 --use_strict Ruby = ruby Scheme = gosh OCaml = ocaml Haskell = runghc DIFF = diff -u START = start.c GOAL = goal.c Q = quine-relay C_EXE = $(Q)-c all: $(GOAL) diff: all $(DIFF) $(START) $(GOAL) $(Q).js: $(START) $(CC) $(CFLAGS) -o $(C_EXE) $< && ./$(C_EXE) > $@ $(Q).rb: $(Q).js $(JavaScript) $< > $@ $(Q).scm: $(Q).rb $(Ruby) $< > $@ $(Q).ml: $(Q).scm $(Scheme) $< > $@ $(Q).hs: $(Q).ml $(OCaml) $< > $@ $(GOAL): $(Q).hs $(Haskell) $< > $@ clean: rm -f $(GOAL) $(C_EXE) $(Q).js $(Q).rb $(Q).scm $(Q).ml $(Q).hs
ãã¨åå¦çç³»ã®ãã¼ã¸ã§ã³ãGaucheã¯éçºçã®ä½ãã
$ clang -v clang version 3.5.0 (tags/RELEASE_350/final) Target: x86_64-apple-darwin13.4.0 Thread model: posix $ echo -n | v8 V8 version 3.25.30 [sample shell] > $ ruby -v ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13] $ gosh -V Gauche scheme shell, version 0.9.5_pre1 [utf-8,pthreads], x86_64-apple-darwin13.4.0 $ ocaml -version The OCaml toplevel, version 4.02.0 $ ghc -V The Glorious Glasgow Haskell Compilation System, version 7.8.3
enumåãããã®ä¸ã®åã¸ã®ãã£ã¹ã
enumåãããã®ä¸ã®åã¸ã®ãã£ã¹ããã underlying_cast
ãæ¸ããã
#include <cinttypes> #include <type_traits> #include <array> #include <cstdio> template <class E> constexpr typename std::underlying_type<E>::type underlying_cast(E e) noexcept { return static_cast<typename std::underlying_type<E>::type>(e); } enum class Ki : std::uint8_t { momo = 3, kuri = 3, kaki = 8 }; template <class T> void p(T n) { std::puts("something"); } template <> void p(std::uint8_t n) { std::printf("uint8_t %" PRIu8 "\n", n); } int main() { p(underlying_cast(Ki::kaki)); std::array<int, underlying_cast(Ki::kaki)> a{}; return 0; }
$ clang++ -std=c++11 -o underlying_cast underlying_cast.cpp $ ./underlying_cast uint8_t 8
ãã£ããã
Cããªããã»ããµãã¯ãæåã¯ã¤ãº
#define STR(a) #a #define STR_(a) STR(a) #define CONCAT(a,b) a##b #define CONCAT_(a,b) CONCAT(a,b) #define M1(a) STR(CONCAT(a, __LINE__)) #define M2(a) STR_(CONCAT(a, __LINE__)) #define M3(a) STR(CONCAT_(a, __LINE__)) #define M4(a) STR_(CONCAT_(a, __LINE__)) int main() { puts(M1(a)); puts(M2(b)); puts(M3(c)); puts(M4(d)); }
以ä¸ã®ãã㪠foo.c
ãããã¨ãã¦ã
$ clang -E foo.c | sed '/^#/d'
ããã¨ã©ããªãããã¤ã¾ããããªããã»ããµãéãã¨ã©ããªããã
ç¶ããèªãmethod-missingãä½ã£ã¦ã¿ã
å¢ãä½ã£ã¦ãé©ç¨ã§ããã¡ã½ããããªããã° method-missing ãå¼ã³åºããæ©è½ãä½ã£ã¦ã¿ãï¼
(define-generic method-missing) (define-class <method-missing-generic> (<generic>) ()) (define-method apply-methods ((gf <method-missing-generic>) methods args) (if (null? methods) (apply method-missing gf args) (next-method)))
ããã¥ã¡ã³ãããªãã¦æ¨æ¸¬ã ãã©ï¼apply-methods
ã¯(sort-applicable-methods
ã§)ã½ã¼ããããé©ç¨å¯è½ãªã¡ã½ããã®ãªã¹ããåãåãï¼next-method
ã次ã®ã¡ã½ãããå¼ã³åºãããã«è¨å®ãã¦ï¼ã¡ã½ãããå¼ã³åºãã®ã ããï¼ã¨ã«ããé©ç¨å¯è½ãªã¡ã½ããããªãã¦ã apply-methods
ã¯(空ãªã¹ããä¼´ã£ã¦)å¼ã°ããããã ï¼
(define-generic foo :class <method-missing-generic>) (define-method foo ((num <number>)) `(number ,num)) (define-method method-missing ((gf <method-missing-generic>) (str <string>) :rest args) `(missing ,(~ gf 'name) string ,str)) (foo 42) ; => (number 42) (foo "bar") ; => (missing foo string "bar") (define-method foo ((num <string>)) `(string ,num)) (foo "bar") ; => (string "bar")
å¼ã³åºãã¸ã§ããªãã¯ãã¡ã³ã¯ã·ã§ã³ foo
ã¯äºãå®ç¾©ãã¦ãããªãã¨ãããªãã®ã§æãé£ã¿ã¯èãæ°ãããï¼