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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:47:17+00:00 2026-06-02T20:47:17+00:00

I will explain what I mean by restricted scope first: restrictedScope (allowedNamespace) { /*

  • 0

I will explain what I mean by restricted scope first:

restrictedScope (allowedNamespace) {
   /* THE CLIENT CODE GOES HERE */
   /* the namespace in this closure is limited only to the idioms
      I allow, both in terms of reserved words and standard functions */

   val result = allowedNamespace.run(); // works, since run() ...
   // ... is a function of allowedNamespace
   val list = new List(); // does not work, since List is not in scope

   /* CLIENT CODE SAMPLE (prepare, release and wait are defined in allowedNamespace) */
   prepare( "service 1" )
   wait( 1000 )
   release( "service 1" )
   ...

}

While executing a strictly imperative DSL based on regular scala code, I would like to run the client code safely. And to do this safely, I might want to restrict the usage of constructions like for and if (only if possible), remove the creation of lists and allow only the idioms I define in allowed namespace to be executed/referred to.

Are there facilities to do this, without overriding all standard idioms?

If not, is there an automatic way (probably via reflection) to override all standard idioms imported to the namespace?

  • 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-02T20:47:19+00:00Added an answer on June 2, 2026 at 8:47 pm

    This might be possible to do with experimental macros in Scala 2.10 which would allow you to inspect the code inside restrictedScope before compiling.

    However, I think you’ll have a hard time filtering the tree for allowed and forbidden methods. So I am not sure this is feasible.

    Alternatively, you could make use of the experimental scala-virtualized branch which at least would allow you to simply overload for and if statements to your own liking. (Reference)

    Yet, this also requires shipping your own compiler so it really depends on the scope of your problem and the target user base. (Some more info on Scala DSLs.)

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

Sidebar

Related Questions

I am trying to reduce some code here. I will explain how I have
First I will explain what I am trying to do. I am trying to
I have problem adding arraylist to list view, will explain about my problem here..
I will try to explain a simple app scenario: My app goes right to
First I will try to explain what I want to do. The app loads
I will first explain why I need it, because I anticipate that the first
This will be a bit difficult to explain but I will try my best.
Okay, let's see if I can explain what I mean, here's an image to
This is an interesting problem, and I will do my best to explain. If
First let me explain you what I mean by a nested transaction. Example: say

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.