企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 概述 ## 16.2.1 把图 16.1 中的文件系统转化为 Scheme 表示 ``` (define dir (list (list 'part1 'part2 'part3) (list (list (list 'hang 'draw) (list 'read!))) 'read!)) ``` ## 16.2.2 开发函数 how-many,该函数读入一个 dir,返回该 dir 树中的文件数 ``` (define (how-many dir) (cond [(empty? dir) 0] [(symbol? (first dir)) (+ 1 (how-many (rest dir)))] [else (+ (how-many (first dir)) (how-many (rest dir)))])) (define dir (list (list 'part1 'part2 'part3) (list (list (list 'hang 'draw) (list 'read!))) 'read!)) (how-many dir) ;7 ``` ## 16.3.2 ![UTOOLS1582168595590.png](http://yanxuan.nosdn.127.net/1106c0ef71f32011e0976899a5fb9f04.png) 习题 16.3.2 开发函数 how-many,该函数读入一个(依照模型三的)dir,返回该 dir 树中的文件数。 ``` (define-struct file (name size content)) (define-struct dir (name dirs files)) ;; 定义目录树 (define dir-list (make-dir 'ts (list (make-dir 'Text empty (list (make-file 'part1 99 empty) (make-file 'part2 52 empty) (make-file 'part3 17 empty))) (make-dir 'Libs (list (make-dir 'Code empty (list (make-file 'hand 8 empty) (make-file 'draw 2 empty))) (make-dir 'Docs empty (list (make-file 'read! 19 empty)))) empty)) (list (make-file 'read! 10 empty)) )) ```