commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r3370 - gnuradio/branches/developers/eb/mb/pmt/src/lib


From: eb
Subject: [Commit-gnuradio] r3370 - gnuradio/branches/developers/eb/mb/pmt/src/lib
Date: Mon, 21 Aug 2006 18:12:31 -0600 (MDT)

Author: eb
Date: 2006-08-21 18:12:31 -0600 (Mon, 21 Aug 2006)
New Revision: 3370

Modified:
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
   gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
Log:
added nth and nthcdr

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc       2006-08-21 
23:42:21 UTC (rev 3369)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.cc       2006-08-22 
00:12:31 UTC (rev 3370)
@@ -762,3 +762,31 @@
   return pmt_reverse(list);
 }
 
+pmt_t
+pmt_nth(size_t n, pmt_t list)
+{
+  pmt_t t = pmt_nthcdr(n, list);
+  if (pmt_is_pair(t))
+    return pmt_car(t);
+  else
+    return PMT_NIL;
+}
+
+pmt_t
+pmt_nthcdr(size_t n, pmt_t list)
+{
+  if (!(pmt_is_null(list) || pmt_is_pair(list)))
+    throw pmt_wrong_type("pmt_nthcdr", list);
+    
+  while (n > 0){
+    if (pmt_is_pair(list)){
+      list = pmt_cdr(list);
+      n--;
+    }
+    if (pmt_is_null(list))
+      return PMT_NIL;
+    else
+      throw pmt_wrong_type("pmt_nthcdr: not a LIST", list);
+  }
+  return list;
+}

Modified: gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h
===================================================================
--- gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h        2006-08-21 
23:42:21 UTC (rev 3369)
+++ gnuradio/branches/developers/eb/mb/pmt/src/lib/pmt.h        2006-08-22 
00:12:31 UTC (rev 3370)
@@ -508,6 +508,17 @@
   return pmt_cons(pmt_cons(x, y), a);
 }
 
+/*!
+ * \brief locates \p nth element of \n list where the car is the 'zeroth' 
element.
+ */
+pmt_t pmt_nth(size_t n, pmt_t list);
+
+/*!
+ * \brief returns the tail of \p list that would be obtained by calling
+ * cdr \p n times in succession.
+ */
+pmt_t pmt_nthcdr(size_t n, pmt_t list);
+
 /*
  * ------------------------------------------------------------------------
  *                          read / write





reply via email to

[Prev in Thread] Current Thread [Next in Thread]