{"id":1597,"date":"2013-01-17T09:26:15","date_gmt":"2013-01-17T00:26:15","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=1597"},"modified":"2018-11-14T16:33:57","modified_gmt":"2018-11-14T07:33:57","slug":"c%e8%a8%80%e8%aa%9e%e3%81%8b%e3%82%89gauche%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%ef%bc%81-3-%e3%83%aa%e3%82%b9%e3%83%88%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2013\/01\/17\/c%e8%a8%80%e8%aa%9e%e3%81%8b%e3%82%89gauche%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%ef%bc%81-3-%e3%83%aa%e3%82%b9%e3%83%88%e6%93%8d%e4%bd%9c\/","title":{"rendered":"C\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (3) \u30ea\u30b9\u30c8\u64cd\u4f5c"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u300cC\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01\u300d\u30b7\u30ea\u30fc\u30ba\u3067\u3059\u3002<\/p>\n<p>\u300c<a title=\"C\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (2) \u57fa\u672c\u7684\u306a\u5024\u306e\u751f\u6210\" href=\"http:\/\/www.techscore.com\/blog\/2013\/01\/16\/c%e8%a8%80%e8%aa%9e%e3%81%8b%e3%82%89gauche%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%ef%bc%81-2-%e5%9f%ba%e6%9c%ac%e7%9a%84%e3%81%aa%e5%80%a4%e3%81%ae%e7%94%9f%e6%88%90\/\">C\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (2) \u57fa\u672c\u7684\u306a\u5024\u306e\u751f\u6210<\/a>\u300d\u306b\u7d9a\u3051\u3066\u3001\u4eca\u56de\u306f\u30ea\u30b9\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Scm_Cons \u95a2\u6570<\/h2>\n<p>Scm_Cons \u95a2\u6570\u306f cons \u30bb\u30eb\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">ScmObj list;\r\nlist = Scm_Cons(SCM_MAKE_INT(3), SCM_NIL);\r\nlist = Scm_Cons(SCM_MAKE_INT(2), list);\r\nlist = Scm_Cons(SCM_MAKE_INT(1), list);<\/pre>\n<p>\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u4ee5\u4e0b\u306e Scheme \u30b3\u30fc\u30c9\u3068\u540c\u3058\u3067\u3059\u3002<\/p>\n<pre class=\"lang:scheme decode:true\">(cons 1 (cons 2 (cons 3 '())))<\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3068 Scheme \u306e\u30b3\u30fc\u30c9\u3068\u898b\u305f\u76ee\u304c\u8fd1\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">Scm_Cons(SCM_MAKE_INT(1),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Scm_Cons(SCM_MAKE_INT(2),\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Scm_Cons(SCM_MAKE_INT(3), SCM_NIL)));<\/pre>\n<p>&nbsp;<\/p>\n<h2>SCM_LISTn \u30de\u30af\u30ed<\/h2>\n<p>\u8981\u7d20\u6570\u304c 1 \u301c 5 \u306e\u30ea\u30b9\u30c8\u3092\u624b\u8efd\u306b\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u3001SCM_LIST1 \u301c SCM_LIST5 \u3068\u3044\u3046\u30de\u30af\u30ed\u3082\u6e96\u5099\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">#define SCM_LIST1(a)             Scm_Cons(a, SCM_NIL)\r\n#define SCM_LIST2(a,b)           Scm_Cons(a, SCM_LIST1(b))\r\n#define SCM_LIST3(a,b,c)         Scm_Cons(a, SCM_LIST2(b, c))\r\n#define SCM_LIST4(a,b,c,d)       Scm_Cons(a, SCM_LIST3(b, c, d))\r\n#define SCM_LIST5(a,b,c,d,e)     Scm_Cons(a, SCM_LIST4(b, c, d, e))<\/pre>\n<p>\u5b9a\u7fa9\u3092\u898b\u308c\u3070\u4e00\u76ee\u77ad\u7136\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">SCM_LIST3(SCM_MAKE_INT(1), SCM_MAKE_INT(2), SCM_MAKE_INT(3));<\/pre>\n<p>\u69cb\u7bc9\u3059\u308b\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u6570\u304c\u56fa\u5b9a\u3067\u3042\u308b\u5834\u5408\u306f\u3001\u4e0a\u8a18\u30de\u30af\u30ed\u3092\u4f7f\u7528\u3059\u308b\u3068\u4fbf\u5229\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>Scm_List \u95a2\u6570<\/h2>\n<p>Scm_List \u95a2\u6570\u306f\u3001\u53ef\u5909\u500b\u306e\u5f15\u6570\u304b\u3089\u30ea\u30b9\u30c8\u3092\u751f\u6210\u3059\u308b\u95a2\u6570\u3067\u3059\u3002<\/p>\n<p>\u4f7f\u3044\u65b9\u306f\u96e3\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u6700\u5f8c\u306e\u5f15\u6570\u3068\u3057\u3066 NULL \u3092\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:c decode:true\">Scm_List(SCM_MAKE_INT(3), SCM_MAKE_INT(2), SCM_MAKE_INT(1), NULL);<\/pre>\n<p>\u203b\u88dc\u8db3\u3067\u3059\u304c\u3001C\u8a00\u8a9e\u3067\u53ef\u5909\u500b\u306e\u5f15\u6570\u3092\u53d6\u308b\u95a2\u6570\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u3001\u5f15\u6570\u3068\u3057\u3066\u300c\u5f15\u6570\u306e\u6570\u300d\u3092\u6e21\u3059\u304b\u3001\u6700\u5f8c\u306e\u5f15\u6570\u306b NULL \u306a\u3069\u306e\u7279\u5b9a\u306e\u5024\u3092\u6e21\u3059\u3053\u3068\u304c\u4e00\u822c\u7684\u3067\u3059\u3002Scm_List \u306f\u5f8c\u8005\u306e\u65b9\u6cd5\u3067\u3001\u6700\u5f8c\u306b NULL \u304c\u6e21\u3055\u308c\u308b\u524d\u63d0\u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30ea\u30b9\u30c8\u306e\u64cd\u4f5c: Scm_Car, Scm_Cdr \u95a2\u6570<\/h2>\n<p>Scheme \u3067\u30ea\u30b9\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u3068\u304d\u306e\u57fa\u672c\u306f\u3001car \u3068 cdr \u3067\u3059\u3002<\/p>\n<p>Gauche \u3067\u306f car \u3068 cdr \u306b\u76f8\u5f53\u3059\u308b Scm_Car \u3068 Scm_Cdr \u95a2\u6570\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u6570\u5024\u306e\u307f\u3092\u542b\u3080\u5358\u7d14\u306a\u30ea\u30b9\u30c8\u306e\u5024\u3092\u8868\u793a\u3059\u308b\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30eb\u30fc\u30d7\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">#include &lt;stdio.h&gt;\r\n#include &lt;gauche.h&gt;\r\n\r\nint main()\r\n{   \r\n    ScmObj p;\r\n    ScmObj list;\r\n\r\n    GC_INIT();\r\n    Scm_Init(GAUCHE_SIGNATURE);\r\n\r\n    list = SCM_LIST3(SCM_MAKE_INT(1), SCM_MAKE_INT(2), SCM_MAKE_INT(3));\r\n\r\n    for(p = list; SCM_PAIRP(p); p = Scm_Cdr(p)) {\r\n        printf(\"%ld\\n\", SCM_INT_VALUE(Scm_Car(p)));\r\n    }\r\n\r\n    return 0;\r\n}<\/pre>\n<p>for \u30eb\u30fc\u30d7\u306e\u3068\u3053\u308d\u3067\u306f\u3001list \u306e\u5148\u982d\u304b\u3089 Scm_Cdr \u3067\u9806\u756a\u306b\u8fbf\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30eb\u30fc\u30d7\u306e\u5185\u5074\u3067\u306f\u3001Scm_Car \u3067\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3057\u3001\u305d\u308c\u3092\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5b9f\u884c\u3059\u308b\u3068\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059\uff08\u203b\u300c<a title=\"C\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (1) \u30b3\u30f3\u30d1\u30a4\u30eb\u74b0\u5883\u3092\u6574\u3048\u308b\" href=\"http:\/\/www.techscore.com\/blog\/2013\/01\/15\/c%e8%a8%80%e8%aa%9e%e3%81%8b%e3%82%89gauche%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%ef%bc%81-1-%e3%82%b3%e3%83%b3%e3%83%91%e3%82%a4%e3%83%ab%e7%92%b0%e5%a2%83%e3%82%92%e6%95%b4%e3%81%88%e3%82%8b\/\">C\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (1)<\/a>\u300d\u3067\u4f5c\u6210\u3057\u305f Makefile \u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\uff09\u3002<\/p>\n<pre class=\"lang:sh decode:true\">&gt; make run\r\n1\r\n2\r\n3<\/pre>\n<p>\u540c\u69d8\u306e\u51e6\u7406\u3092\u884c\u3046 SCM_FOR_EACH \u3068\u3044\u3046\u30de\u30af\u30ed\u3082\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u4e0a\u8a18\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u306a\u304a\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c decode:true\">#include &lt;stdio.h&gt;\r\n#include &lt;gauche.h&gt;\r\n\r\nint main()\r\n{   \r\n    ScmObj p;\r\n    ScmObj list;\r\n\r\n    GC_INIT();\r\n    Scm_Init(GAUCHE_SIGNATURE);\r\n\r\n    list = SCM_LIST3(SCM_MAKE_INT(1), SCM_MAKE_INT(2), SCM_MAKE_INT(3));\r\n\r\n    SCM_FOR_EACH(p, list) {\r\n        printf(\"%ld\\n\", SCM_INT_VALUE(Scm_Car(p)));\r\n    }\r\n\r\n    return 0;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u305d\u306e\u4ed6\u306e\u30ea\u30b9\u30c8\u64cd\u4f5c<\/h2>\n<p>\u4ed6\u306b\u3082\u30ea\u30b9\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u591a\u304f\u306e\u95a2\u6570\u306f\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>Scheme \u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u30ea\u30b9\u30c8\u64cd\u4f5c\u7528\u306e\u624b\u7d9a\u304d\u306b\u5bfe\u5fdc\u3059\u308b C \u8a00\u8a9e\u95a2\u6570\u304c\u5b58\u5728\u3057\u307e\u3059\u3002<\/p>\n<p>\u3044\u304f\u3064\u304b\u8a66\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:c decode:true\">\/* \u30ea\u30b9\u30c8\u306e\u9577\u3055\u3092\u53d6\u5f97\u3059\u308b *\/\r\nScm_Length(list); \/* (length list) *\/\r\n\r\n\/* \u8981\u7d20\u3092\u53cd\u8ee2\u3057\u305f\u30ea\u30b9\u30c8\u3092\u751f\u6210\u3059\u308b *\/\r\nScm_Reverse(list); \/* (reverse list) *\/\r\n\r\n\/* \u8907\u6570\u306e\u30ea\u30b9\u30c8\u3092\u7d50\u5408\u3057\u305f\u30ea\u30b9\u30c8\u3092\u751f\u6210\u3059\u308b *\/\r\nScm_Append(SCM_LIST(list1, list2)); \/* (append list1 list2) *\/<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u524d\u56de\u306f\u5024\u306e\u751f\u6210\u3001\u4eca\u56de\u306f\u30ea\u30b9\u30c8\u64cd\u4f5c\u306b\u3064\u3044\u3066\u8abf\u3079\u307e\u3057\u305f\u3002<\/p>\n<p>\u6b21\u56de\u306f\u6587\u5b57\u5217\u3068\u3057\u3066\u7528\u610f\u3057\u305f Scheme \u30b3\u30fc\u30c9\u3092 eval \u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3001\u9234\u6728\u3067\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u300cC\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01\u300d\u30b7\u30ea\u30fc\u30ba\u3067\u3059\u3002<\/p>\n<p>\u300cC\u8a00\u8a9e\u304b\u3089Gauche\u3092\u4f7f\u304a\u3046\uff01 (2) \u57fa\u672c\u7684\u306a\u5024\u306e\u751f\u6210\u300d\u306b\u7d9a\u3051\u3066\u3001\u4eca\u56de\u306f\u30ea\u30b9\u30c8\u3092\u64cd\u4f5c\u3059\u308b\u65b9\u6cd5\u3092\u8abf\u3079\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2013\/01\/17\/c%e8%a8%80%e8%aa%9e%e3%81%8b%e3%82%89gauche%e3%82%92%e4%bd%bf%e3%81%8a%e3%81%86%ef%bc%81-3-%e3%83%aa%e3%82%b9%e3%83%88%e6%93%8d%e4%bd%9c\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[85,18],"tags":[79,78,77],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1597"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=1597"}],"version-history":[{"count":1,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1597\/revisions"}],"predecessor-version":[{"id":17977,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/1597\/revisions\/17977"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=1597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=1597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=1597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}