【发布时间】:2019-11-23 10:55:20
【问题描述】:
我是 mozart oz 的新手,我有这个问题要解决:
a) Implement a function Zip that takes a pair Xs#Ys of two lists Xs and Ys (of the
same length) and returns a pairlist, where the first field of each pair is taken
from Xs and the second from Ys. For example, {Zip [a b c]#[1 2 3]} returns the
pairlist [a#1 b#2 c#3].
b) The function UnZip does the inverse, for example {UnZip [a#1 b#2 c#3]}
returns [a b c]#[1 2 3]. Give a specification and implementation of UnZip.
我所知道的是# 是某种标签,它构成一对/元组,取自文档,但我找不到说明如何使用它的示例。
我的问题是如何拆分它以获取项目或如何使用该标签(或任何可能有如何使用它的示例的来源)。
我做了一些搜索,我得到了这段代码(我不知道它在语法上是否正确):
declare
fun {Zip L}
case L of nil then nil
[] L1#L2 then .... % Here i'm stuck or i don't know how to proceed
end
end
{Browse {Zip ['a' 'b' 'c']#[1 2 3]}}
任何帮助将不胜感激。
感谢您的宝贵时间。
【问题讨论】: