• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. Adding a variable to a Scheme / SKILL++ environment after...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 142
  • Views 5811
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Adding a variable to a Scheme / SKILL++ environment after its definition

AurelBuche
AurelBuche over 1 year ago

Hi All,

I was wondering if there is a way to add a variable to a SKILL++ environment (obtained using `theEnvironment') after its definition

Using `eval' does not work (which is normal as it is the documented behavior):

For SKILL++'s eval, if the given environment is not the top-level one, the effect is like evaluating g_expression within a let construct for the bindings in the given environment, with the following exception:
If g_expression is a definitional form (such as (define ...)), it is treated as a global definition instead of local one. Therefore any variables defined will still exist after executing the eval form.

Small example here : 

(inScheme

  (let (new_env)
    (setq new_env (theEnvironment))

    (defglobalfun get_new_env nil new_env)
    )

  (eval (setq new_var 12) (get_new_env))

  (get_new_env)->??
  )
;;  => ((new_env envobj@0x375ed800)))
;; new_var is missing

The concrete case is here, I want to create a custom environment allowing me to override any function (even Core ones) : 

;; =======================================================
;; Global function to access custom environment anywhere
;; =======================================================

(let (_custom_env_)

  (setq _custom_env_ (theEnvironment))

  (defun hiDisplayForm (form @optional (position -1:-1))
    "`hiDisplayForm' wrapper to place form under cursor by default"
    ((getd 'hiDisplayForm) form position))

  (defglobalfun custom_env (@rest _args)
    "Return CUSTOM environment"
    _custom_env_)

  );closure

;; =======================================================
;; Global function to load a file in custom environment
;; =======================================================

(let ()

  (defun get_file_sexps (file "t")
    "Return Lisp S-expressions defined in FILE"
    ;; Properly open file
    (let ((port  (infile file))
          (sexps (tconc nil nil))
          sexp)
      ;; Read S-expressions using `lineread'
      ;; Also make sure port is closed
      (unwindProtect
        (while (setq sexp (lineread port))
          (unless (eq t sexp) (lconc sexps sexp))
          )
        (close port)
        )
      ;; `cdar' used to compensate the use of (tconc nil nil)
      (cdar sexps)))

  (defglobalfun custom_load (file @rest _args "tg")
    "Load FILE in custom SKILL++ environment"
    ;; Support symbolic links in file path
    (setq file (simplifyFilename file))
    (assert (and (isFile file) (isReadable file)) "Unable to read %A"      file)
    (assert (pcreMatchp "\\.ils$" file)           "Not a SKILL++ file: %A" file)
    ;; Load file in custom environment
    (eval (cons 'progn (get_file_sexps file)) (custom_env))
    )

  );closure

;; =======================================================
;; Macro to evaluate S-expressions in custom environment
;; =======================================================

(setf custom_closure._fdoc "Evaluate BODY S-expressions in custom environment")
(defmacro custom_closure (@rest body)
  `(eval ',(cons 'progn body) (custom_env)))


/* TEST

;(custom_load "~/skill/test.ils")
(custom_closure

(setq load custom_load) (defun display_example_form nil (hiDisplayForm (hiCreateLayoutForm 'example_form "Example" (hiCreateFormLayout 'main_layout ?items (list (hiCreateLabel ?name 'label ?labelText "TOTO") )) ?maxSize 500:10000) )
) );custom_closure (custom_env)->?? ;*/

I would like to know if it is possible to add wrapper functions afterwards (as done in the "TEST" part) or SKILL++ is limited (environments are immutable) and everything has to be defined in the initial `let' containing `custom_env' ?

Cheers,

Aurélien

  • Cancel
  • Andrew Beckett
    Andrew Beckett over 1 year ago

    Aurélien,

    I'm pretty certain this is not possible. Obviously doing this would be subverting the lexical scoping mechanism - any function added really would not be lexically scoped in that environment but fooling the system to think that it was.

    You can change the values of variables in the environment object (this is mostly intended for debug purposes), but if you try to add new variables they are just properties on the object rather than being truly part of the lexical environment. I completely get why you want do this, but it's not supported.

    Regards,

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • AurelBuche
    AurelBuche over 1 year ago in reply to Andrew Beckett

    Hi Andrew,

    Thanks for your quick reply. That's what I thought.

    If I replace my calls to `load' with `custom_load' in most of my scripts I will already have something close to what I expect.

    And limiting the overriding functions to one environment will be safer anyway.
    It will also be closer to the current behavior as global functions will stay that way.

    Cheers,

    Aurélien

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information