模拟 Python 在 Scheme 中的范围 [英] Analog of Python's range in Scheme

查看:45
本文介绍了模拟 Python 在 Scheme 中的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Scheme 中创建一个连续数字的列表?

How to create a list of consecutive numbers in Scheme?

在 Python 中创建从 1 到 10 的整数列表将是 range(1,11).Scheme 有等价物吗?

In Python to create a list of integers from 1 to 10 would be range(1,11). Is there an equivalent for Scheme?

mzscheme --version 给予 欢迎使用 Racket v5.2.1.

编辑:根据https://stackoverflow.com/a/7144310/596361要实现范围功能,需要此代码:

Per https://stackoverflow.com/a/7144310/596361 to implement range functionality, this code is needed:

#lang racket
(require srfi/1)
(iota 5 1)

推荐答案

寻找 iota(在 SRFI-1 中定义).

Look for iota (as defined in SRFI-1).

示例:(iota 10 1) 给出从 1 开始的 10 个连续整数(而不是默认值 0).

Example: (iota 10 1) gives 10 consecutive integers starting from 1 (instead of the default of 0).

iota 不采用与 range 相同的参数,但它复制了所有功能 - 升序范围、降序范围、如果只给出一个界限,则从 0 开始,以及指定区间的能力.

iota doesn't take the same arguments as range but it duplicates all the functionality - ascending ranges, descending ranges, starting from 0 if only one bound is given, ability to specify the interval.

这篇关于模拟 Python 在 Scheme 中的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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