Home > Community > Blogs > Custom IC Design > skill for the skilled introduction to classes part 1
 
Login with a Cadence account.
Not a member yet?
Create a permanent login account to make interactions with Cadence more conveniennt.

Register | Membership benefits
Get email delivery of the Custom IC Design blog (individual posts).
 

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

SKILL for the Skilled: Introduction to Classes -- Part 1

Comments(2)Filed under: Custom IC Design, Virtuoso, SKILL, Team SKILL, Allegro, programming, LISP, SKILL++, object orientation, object system, Sodoku, classes

In the previous couple of SKILL for the Skilled postings, we looked at some of the features of SKILL++. In fact, we saw local functions, higher-order functions, and lexical scoping. Still another set of features of SKILL++ is called the SKILL++ Object System. This system provides a standardized way of implementing object oriented SKILL applications.

Object Orientation

An Object System is a programming language feature which allows the programmer to control the characteristics and behavior of groups of objects in an organized and coherent way -- in effect making certain types of problems easier to solve.

If you are familiar with C++, Java, or similar programming languages, you might think that Object Orientation is that thing which C++/Java does. I would suggest to abandon that restrictive misconception. One of the first languages to introduce the concepts of object orientation was lisp during the 1970s, long before C++ or Java existed. The SKILL++ object system is based on this lisp approach. I hope the upcoming series of articles begins to peek your interest in this powerful and elegant subset of the SKILL language.

The SKILL++ Object System

SKILL++ strives to make the object system dynamic and reflective. This means you can create classes, and methods on the fly, inspect and debug them, and edit and redefine them in the same VM image. As you learn more about SKILL++ you should be pleasantly surprised at the power of a dynamic object oriented language.

In a nutshell the SKILL++ Object System allows the SKILL programmer to define classes of objects which share (some) structure definition and have similar behavior. Classes define how instances are structured. On the other hand methods on generic functions define how those instances of those classes behave and interact.

The SKILL++ object system provides the capabilities of classes and methods in such a way that they can be used independently or together as the programmer chooses. The means you don't need to understand generic functions and methods to understand classes and instances. In the upcoming series of articles we will look at classes as a tool for solving the Sudoku puzzle.

The Sudoku puzzle

First, what is a Sudoku puzzle? The Sudoku puzzle is a grid divided into nine horizontal rows, nine vertical columns, and nine so-called 3x3 blocks. To solve a sudoku puzzle, you must fill in each blank entry with an appropriately chosen digit from the set {1, 2, 3, 4, 5, 6, 7, 8, 9} such that the rows, columns, and 3x3 blocks each contain all of the numbers from 1 through 9. An implication of this requirement is that each digit must appear exactly once in each row, exactly once in each column, and exactly once in each 3x3 block.

Sudoku in SKILL++

I'd like to implement a SKILL function, SkuSolve, which will work like the following example. The actual example comes from the Sudoku Wikipedia entry.

After we have implemented SkuSolve and its support functions, we should be able to solve any valid Sudoku puzzle as follows.

(SkuSolve '((5 3 ?   ? 7 ?   ? ? ?)
(6 ? ? 1 9 5 ? ? ?)
(? 9 8 ? ? ? ? 6 ?)

(8 ? ? ? 6 ? ? ? 3)
(4 ? ? 8 ? 3 ? ? 1)
(7 ? ? ? 2 ? ? ? 6)

(? 6 ? ? ? ? 2 8 ?)
(? ? ? 4 1 9 ? ? 5)
(? ? ? ? 8 ? ? 7 9)))
This call should print something like the following:

 

starting with: 
+-----+-----+-----+
|5|3| | |7| | | | |
|6| | |1|9|5| | | |
| |9|8| | | | |6| |
|8| | | |6| | | |3|
|4| | |8| |3| | |1|
|7| | | |2| | | |6|
| |6| | | | |2|8| |
| | | |4|1|9| | |5|
| | | | |8| | |7|9|
+-----+-----+-----+

found solution:
+-----+-----+-----+
|5|3|4|6|7|8|9|1|2|
|6|7|2|1|9|5|3|4|8|
|1|9|8|3|4|2|5|6|7|
|8|5|9|7|6|1|4|2|3|
|4|2|6|8|5|3|7|9|1|
|7|1|3|9|2|4|8|5|6|
|9|6|1|5|3|7|2|8|4|
|2|8|7|4|1|9|6|3|5|
|3|4|5|2|8|6|1|7|9|
+-----+-----+-----+

Preview

In the upcoming series we'll look at the following:

  • Defining a class including with inheritance
  • Constructing instances of a class
  • Manipulating instances at run-time
  • Examining the content of an instance

Stay tuned for more to come. Please send submit your questions or comments in the comment section below.

Jim Newton

See Also:

Comments(2)

By chanakaya on September 1, 2011
How difficult will it be to do this without OOP in plain SKILL?


By Team SKILL on September 2, 2011
Thanks for the question.  It's a very good question actually.  As with most simple examples used for teaching purposes, there is usually an easier way.  It would be pretty easy to write this without using OO infact.
This observation is a strength of the SKILL language as a whole.  You may choose to use function programming style, object oriented style, imperative style, or any mix of these as your problem demands.
-jim

Leave a Comment


Name
E-mail (will not be published)
Comment
 I have read and agree to the Terms of use and Community Guidelines.
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.