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 9153777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:19:41+00:00 2026-06-17T12:19:41+00:00

I want to implement a method dim(x,y) which will assign spaces for a matrix(y

  • 0

I want to implement a method dim(x,y) which will assign spaces for a matrix(y rows, x cols).

I want to make “dim(x,y)” more powerful by passing an optional function ‘filler’ to it and then ‘dim’ will set the element located at (x,y) to filler(x,y)

my code goes as below:

List2D dim := method(x, y, z,
    target := list()
    filler := if(z == nil, 
        method(return nil),
        z)
    for(i, 1, y, 
        subTarget := list()
        for(j, 1, x,
            subTarget append( filler(i,j) ))
            target append(subTarget) )
    return target)

it worked well when ‘dim’ is called with 2 arguments,
but failed with

List2D dim(3,2, method(x,y, 10*x+y))

which throwed an exception at line filler := if(z == nil
The exception said nil does not respond to '*'

I realized the argument ‘z’ got activated undesirably when comparing with nil.

So I’m wondering how to get my ‘List2D dim’ work properly?

  • 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-06-17T12:19:42+00:00Added an answer on June 17, 2026 at 12:19 pm

    Alright so basically, you’ll want something like this:

    List2D dim := method(x, y,
        target := list
        blk := call evalArgAt(2) # Get the third argument, and evaluate it in the context of the sender
        if(blk isNil, blk := block setScope(call sender))
    
        for(i, 1, y,
            subTarget := list
            for(j, 1, x,
                subTarget append(blk call(i, j))
                target append(subTarget)
            )
        )
        target
    )
    

    Basically, what’s going on here is since your filler, you want to give it arguments, the easiest method is just to pass in a Block. You can do this with messages, but you in effect, end up setting up your own duplicate of Block anyway if you introduce a new scope, which you should. If the third argument evaluates to nil, then we’ll just create a new function and set its scope to the calling context; as if the user had passed in an empty function, which has no argument arty and as such, you can pass arguments to it even if it doesn’t define any parameters. The fact we scope it to the caller isn’t really needed, but you should always scope blocks to the calling context if you’re creating the blocks inside your method call. This will give access to the lexical scope of the calling context inside that block; which you’re probably shoving some message the user has supplied in it. When ready, just call that method explicitly using the call method.

    If your filler method didn’t require any arguments, I’d just grab the raw message argument at the 2nd index, instead of evaluating it. This would yield some major performance improvements for some large matrices.

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

Sidebar

Related Questions

I want to implement a method that will enable me to find a node
I want to implement a method that will find stuff in my custom class.
I want to implement a generic method on a generic class which would allow
I want to implement my own copy method for a class A which looks
I want to implement a method which takes two Action A1 and Action A2
I want to implement an extension method which converts an enum to a dictionary:
i want to implement a method which takes as an input an integer and
I want to implement a java method which takes URL as input and stores
I want to implement a method in java that could be used to categorize
i'm using ECLiPSe programming logic system. i want to implement the yield method for

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.