Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7542725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:14:33+00:00 2026-05-30T08:14:33+00:00

I’m working on this problem and I got the answers : Statically: 13 Dynamically

  • 0

I’m working on this problem and I got the answers :

Statically: 13

Dynamically -deep binding: 2 <- i’m not sure about this one

Dynamically -shallow binding: 2 <- i’m not sure about this one

is that correct?

Consider the program below (in a Pascal like language). What is the output of the
language is statically scoped? What is the output of the language is dynamically scoped
and uses deep binding? What is the output of the language is dynamically scoped and
uses shallow binding?

Program main;
   x: integer := 2;
   y: integer := 1;
procedure f3(z: integer)
   begin 
       x = z + x + y;
   end
procedure f2(p: procedure, z: integer)
     int x := 5;
   begin
              p(z) 
   end
procedure f1(z: integer)
      int y := z
   begin
     f2(f3,y);
  end

begin /* main program */
f1(4);
       print(x)
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:14:34+00:00Added an answer on May 30, 2026 at 8:14 am

    For the static scope and the dynamic-scope-with-shallow-binding cases, why not try them out? Using Perl with static scope:

    my $x = 2;
    my $y = 1;
    sub f3($) {
      my $z = shift;
      $x = $z + $x + $y;
    }
    sub f2($$) {
      my ($p, $z) = @_;
      my $x = 5;
      $p->($z);
    }
    sub f1($) {
      my $z = shift;
      my $y = $z;
      f2(\&f3, $y);
    }
    f1(4);
    print "$x\n";
    

    I get 7 (which is 4 + 2 + 1). Changing the mys to locals to get dynamic scope with shallow binding, I get 2, as you predicted.

    Testing out dynamic scope with deep binding is trickier, because so few languages support it. In this answer a while back, I posted Perl code that implemented deep binding “manually” by passing around a hash of references to scalars; using that same approach:

    #!/usr/bin/perl -w
    
    use warnings;
    use strict;
    
    # Create a new scalar, initialize it to the specified value,
    # and return a reference to it:
    sub new_scalar($)
      { return \(shift); }
    
    # Bind the specified procedure to the specified environment:
    sub bind_proc(\%$)
    {
      my $V = { %{+shift} };
      my $f = shift;
      return sub { $f->($V, @_); };
    }
    
    my $V = {};
    
    $V->{x} = new_scalar 2;
    $V->{y} = new_scalar 1;
    
    sub f3(\%$) {
      my $V = shift;
      my $z = $V->{z};                 # save existing z
      $V->{z} = new_scalar shift;      # create & initialize new z
      ${$V->{x}} = ${$V->{z}} + ${$V->{x}} + ${$V->{y}};
      $V->{z} = $z;                    # restore old z
    }
    sub f2(\%$$) {
      my $V = shift;
      my $p = shift;
      my $z = $V->{z};                 # save existing z
      $V->{z} = new_scalar shift;      # create & initialize new z
      my $x = $V->{x};                 # save existing x
      $V->{x} = new_scalar 5;          # create & initialize new x
      $p->(${$V->{z}});
      $V->{x} = $x;                    # restore old x
      $V->{z} = $z;                    # restore old z
    }
    sub f1(\%$) {
      my $V = shift;
      my $z = $V->{z};                 # save existing z
      $V->{z} = new_scalar shift;      # create & initialize new z
      my $y = $V->{y};                 # save existing y
      $V->{y} = new_scalar ${$V->{z}}; # create & initialize new y
      f2(%$V, bind_proc(%$V, \&f3), ${$V->{y}});
      $V->{y} = $y;                    # restore old y
      $V->{z} = $z;                    # restore old z
    }
    f1(%$V, 4);
    print "${$V->{x}}\n";
    
    __END__
    

    I get 10 (which is 4 + 2 + 4).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.