Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The enviroment is simple, natural and efficient. The members are competent, educated and professionals..."

Geography

Where in the world do Tek-Tips members come from?

My Problem With My Scheme Program

HZBilal (Programmer)
10 Oct 06 6:53
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 section of my code (at the end) 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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close