[plt-scheme] Scheme Program

From: Bilal, Haider Z (bilalhz at lsbu.ac.uk)
Date: Mon Oct 2 09:50:25 EDT 2006

Dear Sir/Madam,

 

I am a PhD student at LSBU working on 'Measuring Ripple Effect for
Object oriented software'.

I would be extremely grateful for your, or whoever you recommend,
assistance on a problem I'm facing and stuck on!

I have familiarized myself with Scheme and currently working on
writing a Scheme program to list for me all assigned TO and FROM
variables with their line numbers listed. Apart from the red bolded
section of my code shown below, which is supposed to display TO or
FROM to each listed variable appropriately, the rest of my program
working correctly. However, this section of the code is not working
properly and giving me the following error: apply: bad procedure:
#[undefined]

 

A Sample Function of the C program being analysed by the tool we are
using, Codesurfer:

/*
======================================================================
================== */

/* ===========                           biggest_prime
=============== */

/*
======================================================================
================== */

 

int biggest_prime (root)

new_tree_node *root;

{

  /* This function calculates the Biggest prime metric */

 

 int child;

 new_tree_node *parent;

 

 if ( (*root).prime_name[0] != 'P' && biggest_prime_value <
(*(*root).prime).num_of_nodes )

     biggest_prime_value = (*(*root).prime).num_of_nodes;

 

 parent = root->children;

 

 for(child = 0; child < (*root).child_num; child ++)

    if (child == 0)

        biggest_prime (root->children);

    else

       {

         biggest_prime (parent->siblings) ;

         parent = parent->siblings;

       }

 

  return (biggest_prime_value);

}

 

My Program:

(define (assignments)

(define filenumber 1)

   (for-each

      (lambda(pdg)

         (when (eqv? (pdg-kind pdg) 'user-defined)

            (let* ((out-port (open-output-file (string-append "Fun"
(number->string filenumber) "_V.dat"))) (linelist ()))

               (pdg-vertex-set-traverse (pdg-vertices pdg)

                  (lambda(v)

                     (let* ((fileuid (pdg-compilation-uid
(pdg-vertex-pdg v))))

                        (int-pair-set-traverse (pdg-vertex-charpos v)

                           (lambda(offset w)

                              (if (not (equal? (pdg-vertex-ids-killed
v) #f))

                                 (abs-loc-set-traverse
(pdg-vertex-ids-killed v)

                                    (lambda(y)

                                       (let* ((line-num
(file-get-line-num fileuid offset)))

                                          (set! linelist (cons (list
line-num y v) linelist))

                                       )

                                    #t)

                                 )

                              )

                              (if (not (equal? (pdg-vertex-ids-used v)
#f))

                                 (abs-loc-set-traverse
(pdg-vertex-ids-used v)

                                    (lambda(y)

                                       (let* ((line-num
(file-get-line-num fileuid offset)))

                                          (set! linelist (cons (list
line-num y v) linelist))

                                       )

                                    #t)

                                 )

                              )

                           #t)

                        )

                     )

                  #t)

               )

               (set! linelist 

                  (sort linelist

                     (lambda (a b)

                        (< (cadar a) (cadar b))

                     )

                  )

               )

               (for-each

                  (lambda (z)

                     (let ((linenum (car z)))

                        (define line-num (car z))

                        (display (cdr line-num) out-port)

                        (write-char #\tab out-port)

                        (if (not (equal? (pdg-vertex-ids-killed (caddr
z)) #f))

                           (abs-loc-set-traverse
(pdg-vertex-ids-killed (caddr z))

                                 (display "to" out-port)

                           )

                        )

                        (if (not (equal? (pdg-vertex-ids-used (caddr
z)) #f))

                           (abs-loc-set-traverse (pdg-vertex-ids-used
(caddr z))

                                 (display "from" out-port)

                           )

                        )

                        (newline out-port)

                     )

                  )

               linelist)

            (close-output-port out-port))

         (set! filenumber (+ filenumber 1)))

      )

   (sdg-pdgs))

)

(assignments)

 

I have tried to use the lambda function, as shown below:

                        (if (not (equal? (pdg-vertex-ids-killed (caddr
z)) #f))

                           (abs-loc-set-traverse
(pdg-vertex-ids-killed (caddr z))

                              (lambda (x)

                                 (display "to" out-port)

                              #t)

                           )

                        )

                        (if (not (equal? (pdg-vertex-ids-used (caddr
z)) #f))

                           (abs-loc-set-traverse (pdg-vertex-ids-used
(caddr z))

                              (lambda (x)

                                 (display "from" out-port)

                              #t)

                           )

                        )

 

However, it gave me wrong output, some had TO and FROM both listed
together:

(257)     from

(257)     to

(257)     from

(258)     to

(265)     from

(265)     fromfrom

(265)     fromfrom

(266)     tofrom

(266)     tofrom

(268)     tofrom

(268)     tofrom

(270)     fromfrom

(270)     fromfrom

(270)     fromfrom

(270)     to

(270)     fromfrom

(270)     tofrom

(270)     tofrom

(271)     from

(272)     from

(275)     from

(276)     tofrom

(276)     tofrom

(279)     tofrom

(279)     tofrom

 

I would appreciate and value your time in guiding me to what needs to
be done to correct this problem very much please.

 

Thank you.

Yours faithfully,

HZBilal.

 

---
Mr Haider Zuhair Bilal BEng MSc MIEE MIEEE MBCS
PhD Research Scholar
Centre for Systems and Software Engineering
Faculty of Business, Computing and Information Management
London South Bank University
103 Borough Road
London SE1 0AA
UK

 

Tel: +44(0)20 7815 7473
Fax: +44(0)20 7815 7550
Mobile: +44(0)7887 598355

<mailto:bilalhz at lsbu.ac.uk>  

http://myweb.lsbu.ac.uk/~bilalhz/

 




This e-mail message may be confidential and is intended only for the use of the individual(s) to whom it is addressed.  It may contain information which is or may be confidential, non-public or legally privileged. Please do not disseminate or distribute this message other than to its intended recipient without permission of the author. You should not copy it or use it for any purpose nor disclose its contents to any other person. If you have received this message in error, please notify me by email immediately and delete the original message and all copies in your computer systems.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20061002/949f9128/attachment.html>

Posted on the users mailing list.