debugging,lisp,common-lisp , Common-LISP debugging (code included)

Common-LISP debugging (code included)


Tag: debugging,lisp,common-lisp

I hope to get a quick fix to my code, which takes in a list of numbers, numberlist, and a threshold and return the number of items in numberlist that are greater than threshold. I just can't figure out what's wrong, and I am not familiar with debugging. I am very new to stackoverflow, and LISP in general... any comments/criticism/advice will be welcome. Thank you!

ex) (count-greater-than (list 1 2 3 4 5 6 6 7) 5) => 3

(defun count-greater-than (numberlist threshold)
  (if (null numberlist) 0
    (counter (numberlist threshold 0)))
  (defun counter (numberlist threshold count)
    (cond ((null numberlist) count)
          ((> (first numberlist) threshold) (counter (rest numberlist) threshold (+ 1 count)))
          (t (counter (rest numberlist) threshold count)))))


First, note that the standard actually contains functions that will help with things like this. There's a useful count-if function that can take a predicate and count how many elements in a list satisfy it. For your case, you could do:

CL-USER> (count-if #'(lambda (x)
                       (> x 5))
                   (list 1 2 3 4 5 6 6 7))
;=> 3

CL-USER> (defun count-greater-than (numbers threshold)
           (count-if (lambda (n) (> n threshold)) numbers))
CL-USER> (count-greater-than (list 1 2 3 4 5 6 6 7) 5)
CL-USER> (count-greater-than (list 1 2 3 4 5 6 6 7) 6)

In your particular case, it looks like you're doing this manually, but you have the parenthesis wrong. It looks like you're trying to create a local helper function called counter. You can either define it outside the function with defun, e.g.:

(defun count-greater-than (numberlist threshold)
  (if (null numberlist) 0
    (counter (numberlist threshold 0))))

(defun counter (numberlist threshold count)
  (cond ((null numberlist) count)
        ((> (first numberlist) threshold) (counter (rest numberlist) threshold (+ 1 count)))
        (t (counter (rest numberlist) threshold count))))

or you could do it with a local definition, using labels:

(defun count-greater-than (numberlist threshold)
  (labels ((counter (numberlist threshold count)
             (cond ((null numberlist) count)
                   ((> (first numberlist) threshold) (counter (rest numberlist) threshold (+ 1 count)))
                   (t (counter (rest numberlist) threshold count)))))
    (if (null numberlist) 0
        (counter numberlist threshold 0))))


As Xach points out in the comments, you can actually do this even more succinctly using count's :test argument. I don't know whether it captures the notion of "count things with this property" quite as explicitly, but it makes for a very short solution:

CL-USER> (count 5 (list 1 2 3 4 5 6 6 7) :test #'<)
;=> 3

This counts how many times 5 is in the list, but the trick is that rather than checking whether a list element is 5 using eql or =, it uses <. That is, count will end up checking (< 5 1), then (< 5 2), …, up to (< 5 6), (< 5 7). It is specified that the test will be called with the arguments in that order. The glossary entry on satisfy the test says (emphasis added):

  1. (for a two argument test) to be in a state such that the two-place predicate which is the sequence function's test argument returns true when given a first argument that is the object being considered, and when given a second argument that is the result of calling the sequence function's key argument on an element of the sequence function's sequence argument which is being tested for equality;


How can I debug scala.js unit tests?

I have some scala.js unit tests written in utest. They all run just fine from the sbt build, however I would like to be able to step through the unit tests in a debugger. Using my favorite IDE (intellij) to debug the tests won't work because it will try to...

How to convert Solaris MDB addresses into file names and line numbers?

Say you have a MDB stack trace that look like this:`vmem_seg_alloc+0x170`vmem_xalloc+0x628`vmem_alloc+0x1f8`umem_alloc+0xec`malloc+0x40 compute+0x14 main+0x54 _start+0x12c For example a stack trace that is generated when applying ::vmem_seg -v to an address that is listed by ::findleaks. The corresponding binary has debugging symbols included, thus it should be...

Why Eclipse Debugger does not stop on scoped exception breakpoint (how to stop on handled exception)

I am using Eclipse Luna (tested also in Kepler so not version specific). Run on JDK 1.8_40. I would like to find places with "eaten" exceptions - e.g. inproperly handled with try/catch block. Example code below. When I am setting Exception breakpoint as on picture e.printStackTrace() does not stop with...

Insertion into a list doesn't reflect outside function whereas deletion does?

I am new to Lisp. Deletion of an item in a list by a function gets reflected outside the function but insertion doesn't. How can I do the same for insertion? For example (defun test (a b) (delete 1 a) (delete 5 b) (append '(5) b) (member '5 b)) (setq...

What am I doing wrong in my coin flip code?

I am trying to write a program that flips a coin, and displays Heads or Tails accordingly. This is what I have: from random import random while True: for i in range (2): spin = i.random() if spin == 0: print ("Heads") else: print ("Tails") but I keep getting the...

Firefox Add-Ons: Variable Is Not Defined In Console

I'm developing a Firefox extension. When I run it, I open up the browser console and it says, [name] is not defined. It's in "browser.xul." <?xml version="1.0"?> <?xml-stylesheet href="chrome://Uedit/skin/skin.css" type="text/css"?> <!DOCTYPE Uedit SYSTEM "chrome://Uedit/locale/translations.dtd"> <overlay id="Uedit-overlay" xmlns=""> <script src="Uedit.js" /> <toolbarpalette id="BrowserToolbarPalette"> <toolbarbutton id="Uedit"...

Concurrent modification exception when using iterator? (Java)

I am trying to write code for the simulation WaTor in which sharks and fish eat each other and simulate population control etc. Anyways, the problem I am having is that i keep getting a concurrect modification exception even when using an iterator. Here is my code: private void updateSharks()...

Structuring large Lisp applications

I am currently trying to wrap my head around packages, systems & co. I now have read Packages, systems, modules, libraries - WTF? a few times, and I think I'm still having difficulties to get it right. If I simply want to split a Lisp source file into two files,...

ASP.NET strange behaviour: Adding Debug=true in web.config changes css

Just as the question states: When I add debug=true to my web.config (no other changes anywhere in the code) my page is rendered with no background colour. Any explanation why this should occur?...

in clojure, function argument type mismatch

clojure, function argument is vector, but it takes a map without problem. (defn flower-colors [colors] (str "The flowers are " (:flower1 colors) " and " (:flower2 colors))) (flower-colors {:flower1 "red" :flower2 "blue"}) ;; -> "The flowers are red and blue" Function flower-colors suppose to take vector type argument, but with...

iOS how to programmatically read device's screen auto-lock timeout time?

I'm creating a method to send debug info to the support team for one of my apps. I have method calls like these: NSString* appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; NSString* build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];; NSString* iOSVersion = [[UIDevice currentDevice] systemVersion];; An additional requirement is to understand how our internal...

If strings are vectors, why are they immutable?

if strings are vectors of characters, and a vector's elements can be accessed using elt, and elt is setf-able - then why are strings immutable?

Error messages and console logs in Electron?

How do you view error messages and console logs in Electron during development? Also, is it possible for the logs to be written directly into a file? Edit: Kind of like the errors and console logs displayed by Chrome's dev tools: Except in Electron rather than Chrome....

AngularJS: UI-Router blank page debug

I just wondering does anybody know how to debug situation when you have blank page for UI-Router. (Of course, without any errors in console) By doing console.log for router events(take from here) I found you that it went to correct state but after did not stop on breakpoint inside state...

Backquote String Interpolation

Is it possible to use lisp's macro to do string interpolation? For instance, can I make a macro like this: (defmacro test (a) `",a") So that (test abc) returns "abc" as a string? I could probably cheat by quoting it and turning that quote into a string, but that doesn't...

Android Studio missing exception stacktrace in Logcat

For some time, Android Studio doesn't show me stacktrace when developed application crashes. All I can see is following line: 06-09 16:12:36.875 26037-26037/com.a.b W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4206c700) This drives me crazy because I cannot see, where application really crashed (and what exception occurs). I'm using AS...

Print output of a Theano network

I am sorry, very newbee question... I trained a neural network with Theano and now I want to see what it outputs for a certain input. So I can say: test_pred = lasagne.layers.get_output(output_layer, dataset['X_test']) where output_layer is my network. Now, the last layer happens to be a softmax, so if...

Debug java in brackets editor or Visual Studio Code

I really hate the IDE. They are too heavyweight and add a bunch of IDE specific files and folders and whatnot when creating a project. For the sake of making things easier, I use code editors. My favourite are Brackets (found at this site) and microsoft's cross platform Visual Studio...

GET document canceled upon first visit (Chrome)

This is a very strange issue with google chrome that some of my customers are reporting that is happening to them when they first visit my website. Bascially what happens is when they load Chrome for the first time, enter my website domain and press enter. It will load for...

I cannot debug two projects at once - one with Resharper NUnit tests

My team has a solution with multiple projects. One of these projects is an ASP.NET MVC website. Another project contains NUnit tests. We launch these NUnit tests inside Visual Studio 2013 with Resharper 8.2.2. Another developer on my team is able debug both the MVC project and the NUnit tests...

Perl Debugging Using Flags

So my goal is to find an easy way to turn on print statements in Perl a flag. In C/C++ you can use a #define to choose if certain code is run and it is a way to turn on and off debug print statements. Where if a #define DEBUG...

Eclipse Debugger Hitting Comments, Skipping Actual Code

Using Eclipse Luna Service Release 2 (4.4.2) Build id: 20150219-0600 Java Web app running in Tomcat v8.0 (Gold Copy) I've restarted my Eclipse and its debugger numerous times over the course of several days, this has been happening constantly for a few days now, so this is not some random...

Exceed evaluation depth when forward function in Emacs Lisp

Here is just a simplified code snipped I have not managed to work. I do not understand what is wrong. (defun enumerate-indicies (func) (let ((index 0)) (while (< index 5) (funcall func index) (setq index (1+ index))))) (defun enumerate-multiplied-indicies (func) (enumerate-indicies #'(lambda (index) (funcall func (* 10 index))))) The following...

How to drill down into shared_ptr [Netbeans, clang++, gdb]

I'm using Netbeans C++ 8.0.2 clang++ (Ubuntu clang version 3.6.0-2ubuntu1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)) gdb (GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9) In my "C++ Simple Tests," whenever I inspect a variable that is a shared_ptr, all I see for value is: std::shared_ptr (count 1, weak 0) 0x64d3a0 or similar. There...

Rails 4 + delayed job - constantly writing debug code to production logs

I'm using delayed job for the first time, and it seems to be working fine. I started to tail my production log to fix another issue, and found that delayed job is constantly updating the production log with debug code. Is this normal, and can I turn it off? [2015-06-14T16:05:35.983383...

EVAL/APPLY: too many arguments given to F

Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list. (defun f (L) (cond ((NULL l) nil) ((listp (car L)) (append (F(car L))) (F(cdr L) (car (F...

What does the double colon mean in Scope Local variables in Chrome's debugger?

See the screen dump fragment below. Notice that there are two colons between legend and Object (legend is a field of ptd). What does the double colon mean? My problem is that if I test the value of ptd.legend, it is 'undefined'. Which it shouldn't be... ...

BSTD inorder traversal produces erroneous behaviour

I have a BSTD implementation which is inserting values incorrectly and I can't find for the life of me what is going on. EXPECTED ACTUAL -------- ---------- Alex Janice Carlos Janice Elton Janice Janice Zidane Zidane Zidane Implementation private Node<K,E> insert(Node<K,E> node, K key, E elem) { if (node ==...

Debbugging angularjs app without ripple or browser because it uses cordovasqlite plugin

In my AngularJS/Ionic app I use the cordova-sqlite plugin and a local database to store data; I also use a web service to fill the database with data from a remote database. Well, sometimes I get a strange behaviour when I try to get data from the remote database. My...

iOS app crash on launch using XCode debugger, runs fine without debugger

When running the app on a device (iphone), it crashes at startup without any error messages. But if the device is not connected to xcode (not in debug mode), just open up the app, it runs fine. Same code runs perfect on simulator. Never seen this before, I guess something...

Print addresses of all local variables in C

I want to print the addresses of all the local and global variables which are being used in a function, at different points of execution of a program and store them in a file. I am trying to use gdb for this same. The "info local" command prints the values...

VBA Debugger shows only 256 elements of a collection

the title explains my problem. Im working on an excelmakro and my questions is, is there an option that the debugger shows all elements like it does with an array? And if not, is the only workaround the storage of my classobjects in an array after inflating the collection? I...

Java Reflection vs Java Debug Interface (JDI) [closed]

What are the differences between use Java Reflection and Java Debug Interface? when can I use one and when the other?

Suggestions for my Selection Sort / Java

My Selection Sort algorithm is not working. I am getting the following errors: //Exception in thread "main" java.lang.NullPointerException Note: this is for a java class. I do not have a lot of experience. I am done with the assignment. I am trying to understand the reason why my sorting algorithm...

Codecademy “SyntaxError: Unexpected token else”

I'm doing the codecademy js course, and I'm at the part with rock paper scissors. When I save the code it says "SyntaxError: Unexpected token else". What did I do wrong? This is my code: var compare = function(choice1, choice2) { if (choice1 === choice2) { return("The result is a...

Visualise CSS selectors like :read-only in debug (F12 tools)

Having :read-only, [readonly] { background-color: aliceblue; } <form> <h2>test</h2> </form> How can I detect, when debugging, say, in Chrome, that the h2(or form) field has an :read-only property (or other type of selector, like :disabled, etc.) set to true? PS. To clarify the question: the question is not about a...

Invalid specialized parameter in method lambda list

I am trying to write a simple coin flip program in Common Lisp. This is the code I have (defun yn (let ht (random 1) (if (eq ht 1) (princ heads) (princ tails)) ) ) It seems simple enough, but I keep getting the error: "Invalid specialized parameter in method...

Can't find out how button click event got wired

I have a button which posts back through Ajax. I tried to find out what code executes when the button is clicked. I used Visual Event (screen capture below) to see how the event was bound but the info didn't help me enough. Then I set an event listener breakpoint...

Debugging service test client: Netbeans debugger won't recognize Glassfish server

Here's what I've done so far: Did a fresh build of project (web service project). Redeployed project war file to Glassfish server. Restarted server with --debug=true. Attached debugger from Netbeans. Debugger attaches to the server without an error (responds "User Program Running"), however the Debug tab (in the Projects/Files/Services window)...

Outputing logs to Console in Android

I'm using the command line to build a project that I am working on: I use it to generate an APK, transfer it to my device, and then run it in on my device. I am trying to debug this application now, and I am not sure how to go...

What is this error about perllocale in Perldoc?

I was discussing here about setting no locales in Perl and was recommended to run this perldoc perllocale in OSX Yosemite 10.10.3 but I get the error: Error while formatting with Pod::Perldoc::ToMan: at /System/Library/Perl/5.18/Pod/ line 1346. at /usr/bin/perldoc5.18 line 11. Got a 0-length file from /System/Library/Perl/5.18/pods/perllocale.pod via Pod::Perldoc::ToMan!? at /usr/bin/perldoc5.18...

What are my next steps on finding the cause of this exception?

I'm fairly new to Eclipse, Java, and Android programming. I've taken over development of an Android application. Someone has made a change several months ago that is causing the application to crash (exception) in code that is not part of the application code. I don't have any idea where or...

Why am I getting a debug assertion failed error on running the code

When I enter a password in my program below and press enter I get a debug assertion error, specifically isctype.c line 56 Expression:(unsigned)(c+1) <= 256 Could someone help me get around this please? Code: int main() { int j=0; char pass[100]; int upper=0, lower=0, digit=0, sc=0; printf("Enter your password:\n"); scanf("%s",&pass);...

Install Android app on device through wifi - no usb or emulator

Just as it says in the title. It seems my smartphone data connectors are broken, and the emulators run far too slow on my computer (surprisingly because it is i7). So, is there any way I can use an alternative to usb debugging through WIFI instead of usb? ...

How to pass or declare array members in c?

I developed a program that is supposed to pass the following members of the array of double purchase from the following function: float beverages () { char response; double purchase [8]= {3.50, 3.80, 3.90, 4.20, 4.00, 4.30, 3.00, 3.10}; printf("\nEnter your order: "); scanf("%c", response); if (response == 'l') {...

C++ Have lone executable log exceptions?

I'm currently in a beta testing phase of my C++ Server. I'm sending it out to users to stress test it to see if an exceptions show up. However, since the .exe is a standalone, how do I make it so it automatically creates a dump or a log of...

Errors trying to add rectangles to JPanel

I am trying to draw a grid of rectangles on a JPanel that already has a few JButtons on it. I get a big list of errors when I try to run it. Here's my code: package GameOfLife; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*;...

Debugging a SQL command in c#

So below I have a piece of code that I have been working on: SqlConnection connect = new SqlConnection("Server=OMADB01;Database=PATRICK_DEV;Trusted_Connection=True;"); connect.Open(); SqlCommand command = new SqlCommand("UPDATE FILE_DATE_PROCESSED SET FILE_DATE_PROCESSED = DATE_ENTERED, DATE_ENTERED = GETDATE() SELECT top 1 FILE_DATE_PROCESSED, DATE_ENTERED FROM FILE_DATE_PROCESSED, ORDER BY DATE_ENTERED DESC ", connect); SqlDataReader reader = null;...

Can somebody explain why this is the result? [on hold]

public boolean isNumber(String s) { String a = s.trim(); if(a == null || a.isEmpty()){ return false; } boolean dFlag = false; boolean eFlag = false; boolean nFlag = false; for (int i = 0; i< a.length();i++){ char c = a.charAt(i); if (c == '+' || c == '-'){ if (i...

Once I turn off debuggingData in angular, is there another way to get the rootscope?

I think having debugging info on by default in Angular will sink large apps. You can now disable this in production: But there are some cases where I do: angular.element(document).scope() in order to access the rootScope. Is there another way in angular to get the $rootScope without this debugging...