diff options
| author | forsyth <forsyth@vitanuova.com> | 2011-04-07 10:04:31 +0100 |
|---|---|---|
| committer | forsyth <forsyth@vitanuova.com> | 2011-04-07 10:04:31 +0100 |
| commit | 09fa9b42130335ddb8876b9be05f780093519864 (patch) | |
| tree | 502762ed084531ebd86c1aff3bfb112d36f221dc | |
| parent | c2ef9233feb49e4dc90f4f58fc499eb2c607bf7d (diff) | |
20110407-1004
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | appl/lib/lists.b | 34 | ||||
| -rw-r--r-- | dis/lib/lists.dis | bin | 1309 -> 1364 bytes | |||
| -rw-r--r-- | include/version.h | 2 | ||||
| -rw-r--r-- | man/2/lists | 23 | ||||
| -rw-r--r-- | man/2/sys-dup | 28 | ||||
| -rw-r--r-- | module/lists.m | 4 |
7 files changed, 68 insertions, 26 deletions
@@ -1,3 +1,6 @@ +20110407 + fix embarrassingly broken Lists->delete; add Lists->find [issue 257] + add some extra explanation to sys-dup(2) about fildes 20110404 update Nt/386/bin /limbo/com.c - count constants in qualifiers, not qualifiers [issue 212, mechiel] diff --git a/appl/lib/lists.b b/appl/lib/lists.b index 52e007bb..31d26ddb 100644 --- a/appl/lib/lists.b +++ b/appl/lib/lists.b @@ -87,22 +87,30 @@ last[T](l: list of T): T return hd l; } -# delete the first instance of x in l -delete[T](x: T, al: list of T): list of T +# find instance of x in l, return tail of l from x +find[T](x: T, l: list of T): list of T for { T => eq: fn(a, b: T): int; } { - for(l := al; l != nil; l = tl l){ - if(T.eq(x, hd l)){ - o: list of T; - for(; al != l; al = tl al) - o = hd al :: o; - l = tl l; - for(; o != nil; o = tl o) - l = hd o :: l; + for(; l != nil; l = tl l) + if(T.eq(x, hd l)) return l; - } - } - return al; + return nil; +} + +# delete the first instance of x in l +delete[T](x: T, l: list of T): list of T + for { T => eq: fn(a, b: T): int; } +{ + loc := find(x, l); + if(loc == nil) + return l; + o: list of T; + for(; l != loc; l = tl l) + o = hd l :: o; + l = tl loc; + for(; o != nil; o = tl o) + l = hd o :: l; + return l; } pair[T1, T2](l1: list of T1, l2: list of T2): list of (T1, T2) diff --git a/dis/lib/lists.dis b/dis/lib/lists.dis Binary files differindex 58ce79ab..f48dfdd0 100644 --- a/dis/lib/lists.dis +++ b/dis/lib/lists.dis diff --git a/include/version.h b/include/version.h index 66fe5d84..fd472ab7 100644 --- a/include/version.h +++ b/include/version.h @@ -1 +1 @@ -#define VERSION "Fourth Edition (20110406)" +#define VERSION "Fourth Edition (20110407)" diff --git a/man/2/lists b/man/2/lists index ae52ab49..eebcb964 100644 --- a/man/2/lists +++ b/man/2/lists @@ -1,6 +1,6 @@ .TH LISTS 2 .SH NAME -lists: allsat, anysat, append, combine, concat, delete, filter, ismember, last, map, pair, partition, rev, unpair\- list operations +lists: allsat, anysat, append, combine, concat, delete, filter, find, ismember, last, map, pair, partition, rev, unpair\- list operations .SH SYNOPSIS .EX include "lists.m" @@ -11,6 +11,8 @@ combine: fn[T](l1: list of T, l2: list of T): list of T; concat: fn[T](l1: list of T, l2: list of T): list of T; delete: fn[T](x: T, l: list of T): list of T for { T => eq: fn(a, b: T): int; }; +find: fn[T](x: T, l: list of T): list of T + for { T => eq: fn(a, b: T): int; }; ismember: fn[T](x: T, l: list of T): int for { T => eq: fn(a, b: T): int; }; last: fn[T](l: list of T): T; @@ -38,7 +40,7 @@ Reference types are .BR list , .BR module , and -.BI ref "adt". +.BI ref " adt". None of the operations change their parameter lists: they always return a new list. .PP First, there is a group of common list operations. @@ -77,6 +79,23 @@ that returns true (non-zero) if two values of type .I T are considered equal. .PP +.B Find +finds the first instance of +.I x +in list +.I l +and returns the tail of +.I l +with +.I x +at its head. +.B Find +returns nil if there is no +instance of +.I x +in +.IR l . +.PP .B Ismember returns 1 if there is an element of diff --git a/man/2/sys-dup b/man/2/sys-dup index 7b96b47a..2fd45f7b 100644 --- a/man/2/sys-dup +++ b/man/2/sys-dup @@ -21,6 +21,9 @@ or simply `file descriptor' when the context is understood. holds an integer-valued file descriptor, the form used by the operating system, in a structure that can be reference counted and garbage collected. +When the +.B FD +value is reclaimed, the system automatically closes the associated integer file descriptor. There are occasions when a program must access the underlying integer file descriptor, such as when rearranging the standard input and output for a new subprocess. @@ -47,15 +50,22 @@ If a suitable file descriptor cannot be found, returns \-1. .PP .B Fildes -uses the integer file descriptor -.B fd -to create a new Limbo -file descriptor, suitable for other -.B Sys -module functions. -It returns -.B nil -if it cannot convert +duplicates the integer file descriptor +.IR fd , +as if by +.BI "sys->dup(" fd ",-1"), +and returns a reference to the new descriptor as an +.B FD +value, +making it usable by other functions in +.BR Sys , +such as +.IR sys-print (2) +and +.IR sys-read (2). +.B Fildes +returns nil +if it cannot duplicate .IR fd . .SH SEE ALSO .IR sys-intro (2), diff --git a/module/lists.m b/module/lists.m index 5c0678ff..fb6f83ab 100644 --- a/module/lists.m +++ b/module/lists.m @@ -11,7 +11,9 @@ Lists: module concat: fn[T](l: list of T, l2: list of T): list of T; combine: fn[T](l: list of T, l2: list of T): list of T; reverse: fn[T](l: list of T): list of T; - last: fn[T](l: list of T): T; + last: fn[T](l: list of T): T; + find: fn[T](x: T, l: list of T): list of T + for { T => eq: fn(a, b: T): int; }; delete: fn[T](x: T, l: list of T): list of T for { T => eq: fn(a, b: T): int; }; pair: fn[T1, T2](l1: list of T1, l2: list of T2): list of (T1, T2); |
