将数据结构列表转换为字符串、方案 [英] convert a list of data structure in string, scheme

查看:42
本文介绍了将数据结构列表转换为字符串、方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有这个结构:

(define-struct example (n1 n2)) 

我有这个列表:

(list (make-example 1 3) (make-example 7 9) empty)

因为我可以把它转换成字符串吗?

As I can convert it into string?

推荐答案

由于您同时标记了球拍和方案(两种不兼容的语言),因此我在回答中完全忽略了方案.如果您正在编程,我假设您不会标记 在 #!r5rs 或 #!r6rs 中.

Since you have tagged both racket and scheme (two incompatible languages) I've ignored Scheme completely in my answer. I assume you would not tag racket if you were programming in #!r5rs or #!r6rs.

#!racket

(define (any->string any) 
  (with-output-to-string (lambda () (write any))))

(any->string '(Hello world)) ; ==> "(Hello world)"

这篇关于将数据结构列表转换为字符串、方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆