SlideShare a Scribd company logo
1 of 24
Download to read offline
SIP-17 Type Dynamic
          Daegeun Kim (dani.kim@geekple.com)




Monday, January 7, 13
Type Dynamic

               SIP-17 (Scala Improvement Process)
               마틴 오더스키가 제안한 개선사항
               좀 더 유연한 DSLs을 제공하기 위함
               정적 타입의 경우 존재하는 멤버(변수, 메서드 등)만 접근
               하거나 호출할 수 있다.
               그렇다고 런타임시에 뭔가 동적으로 뭔가 수행하는 것은
               아니다.

           DSL : Domain-Specific Language



Monday, January 7, 13
class A

          val a = new A
          println(a.name) // error



           선언된 클래스 A는 name이라는 멤버변수가 없다. 기본적인 내용이지만 짚고 넘어갑니다.



Monday, January 7, 13
SIP-17 : 특징을 알아볼까요!




Monday, January 7, 13
selectDynamic


           존재하지 않는 멤버를 접근하는 경우 멤버명을 파라메터로 selectDynamic을 호출한다.



Monday, January 7, 13
class A extends Dynamic {
            def selectDynamic(name: String) = ...
          }

          val a = new A
          println(a.name) // no error


           존재하지 않는 멤버(변수, 메서드 등)을 접근해도 문제가 발생하지 않고 대신 해당 인스턴스
           의 selectDynamic 메서드에 “name” 문자열을 담은 name과 함께 호출한다.


Monday, January 7, 13
updateDynamic


           존재하지 않는 멤버를 수정하는 경우(xx.method = expr) updateDynamic 메서드가 호출
           한다. 단, update의 경우는 selectDynamic 선언이 필요하다.


Monday, January 7, 13
class A extends Dynamic {
            def updateDynamic(name: String)
          (value: String) { ... }
          }

          val a = new A
          a.name = “Daegeun Kim”

           존재하지 않는 멤버인 name 멤버를 “Daegeun Kim” 으로 변경하는 경우
           updateDynamic(“name”)(“Daegeun Kim”) 으로 호출한다. 위의 선언에서
           selectDynamic은 생략한다. value의 타입이 String일 필요는 없다.

Monday, January 7, 13
applyDynamic


           존재하지 않는 멤버 메서드를 호출하는 경우 메서드명과 함께 입력한 파라메터를
           applyDynamic 메서드의 파라메터로 하여 호출한다.


Monday, January 7, 13
class A extends Dynamic {
            def applyDynamic(name: String)(args:
          Any*) { ... }
          }

          val a = new A
          a.greeting(“Daegeun Kim”)

           존재하지 않는 메서드인 greeting을 접근하는 경우 applyDynamic 메서드 호출하며
           name은 “greeting” args는 WrappedArray(“Daegeun Kim”)이다. args을 굳이 Any* 로
           규정할 필요는 없습니다.

Monday, January 7, 13
applyDynamicNamed


           존재하지 않는 멤버 메서드를 호출하는 경우 메서드명과 함께 입력한 파라메터를
           applyDynamicNamed 메서드의 파라메터로 하여 호출한다. 단, applyDynamic과 다른 점
           은 이름에서도 알 수 있듯이 Named Parameter 형태일 때 호출한다.

Monday, January 7, 13
class A extends Dynamic {
            def applyDynamicNamed(name:
          String)(args: (String, Any)*) { ... }
          }

          val a = new A
          a.greeting(name = “Daegeun Kim”,
          message = “Welcome”)

           존재하지 않는 메서드인 greeting을 접근하는 경우 applyDynamicNamed 메서드 호출하
           며 name은 “greeting” args는 WrappedArray((name,Daegeun Kim),
           (message,Welcome) 이다.

Monday, January 7, 13
사용하려면?


           2.10.0 에서도 간혹 경우에 따라 오류가 나는 경우가 있습니다. 되도록이면 RC버전이 아닌
           2.10.x 버전에서 실행하세요. 2.9버전에서는 -Xexperimental 을 주고 실행하면 되지만 잘
           안됩니다.

Monday, January 7, 13
scalac -language:dynamics

               scala -language:dynamics

               import language.dynamics

           SIP-18 - Modularizing Language Features 추가된 기능이고 dynamics feature를 활
           성화 시키는 방법 설명입니다. SIP-18 또한 2.10 부터 정식 추가된 기능입니다.


Monday, January 7, 13
알고보면 단순한 구조




Monday, January 7, 13
컴파일타임에 코드를 재작성한다.




Monday, January 7, 13
물론, Dynamic 를 붙인 것 만 작업




Monday, January 7, 13
멤버(변수, 메서드) 없을 때만 해당!




Monday, January 7, 13
selectDynamic
          val a = new A
          a.name

          // a.selectDynamic(“name”)


Monday, January 7, 13
updateDynamic
          val a = new A
          a.name = “Daegeun Kim”

          // a.updateDynamic(“name”)
          (“Daegeun Kim”)


Monday, January 7, 13
applyDynamic
          val a = new A
          a.greeting(“Daegeun Kim”)

          // a.applyDynamic(“greeting”)
          (WrappedArray(“Daegeun Kim”))
           이전의 예를 기준으로 했을 때 위와 같이 재작성되고 항상 이렇게 되는건 아닙니다.



Monday, January 7, 13
applyDynamicNamed
          val a = new A
          a.greeting(name = “Daegeun
          Kim”)

          // a.applyDynamic(“greeting”)
          (WrappedArray((name,“Daegeun
          Kim”)))
Monday, January 7, 13
필요한 곳에만 사용합시다.


           필요한 곳에 시기적절하게 사용하는 것이 좋을 것 같고 제안한 목적처럼 유연한 DSL 구조를
           가질 수 있는 곳에 사용하는 것이 좋다고 봅니다.


Monday, January 7, 13
끝


           그럼 이만 마치도록 하겠습니다. 질문이 있으신가요? :-) 성의없지만 이렇게 마무리. 그리고
           틀린 것이 있다면 조언 부탁드립니다.


Monday, January 7, 13

More Related Content

Recently uploaded

A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)Tae Young Lee
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Wonjun Hwang
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Kim Daeun
 
Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Wonjun Hwang
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionKim Daeun
 

Recently uploaded (6)

A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 
Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

SIP-17 Type Dynamic

  • 1. SIP-17 Type Dynamic Daegeun Kim (dani.kim@geekple.com) Monday, January 7, 13
  • 2. Type Dynamic SIP-17 (Scala Improvement Process) 마틴 오더스키가 제안한 개선사항 좀 더 유연한 DSLs을 제공하기 위함 정적 타입의 경우 존재하는 멤버(변수, 메서드 등)만 접근 하거나 호출할 수 있다. 그렇다고 런타임시에 뭔가 동적으로 뭔가 수행하는 것은 아니다. DSL : Domain-Specific Language Monday, January 7, 13
  • 3. class A val a = new A println(a.name) // error 선언된 클래스 A는 name이라는 멤버변수가 없다. 기본적인 내용이지만 짚고 넘어갑니다. Monday, January 7, 13
  • 4. SIP-17 : 특징을 알아볼까요! Monday, January 7, 13
  • 5. selectDynamic 존재하지 않는 멤버를 접근하는 경우 멤버명을 파라메터로 selectDynamic을 호출한다. Monday, January 7, 13
  • 6. class A extends Dynamic { def selectDynamic(name: String) = ... } val a = new A println(a.name) // no error 존재하지 않는 멤버(변수, 메서드 등)을 접근해도 문제가 발생하지 않고 대신 해당 인스턴스 의 selectDynamic 메서드에 “name” 문자열을 담은 name과 함께 호출한다. Monday, January 7, 13
  • 7. updateDynamic 존재하지 않는 멤버를 수정하는 경우(xx.method = expr) updateDynamic 메서드가 호출 한다. 단, update의 경우는 selectDynamic 선언이 필요하다. Monday, January 7, 13
  • 8. class A extends Dynamic { def updateDynamic(name: String) (value: String) { ... } } val a = new A a.name = “Daegeun Kim” 존재하지 않는 멤버인 name 멤버를 “Daegeun Kim” 으로 변경하는 경우 updateDynamic(“name”)(“Daegeun Kim”) 으로 호출한다. 위의 선언에서 selectDynamic은 생략한다. value의 타입이 String일 필요는 없다. Monday, January 7, 13
  • 9. applyDynamic 존재하지 않는 멤버 메서드를 호출하는 경우 메서드명과 함께 입력한 파라메터를 applyDynamic 메서드의 파라메터로 하여 호출한다. Monday, January 7, 13
  • 10. class A extends Dynamic { def applyDynamic(name: String)(args: Any*) { ... } } val a = new A a.greeting(“Daegeun Kim”) 존재하지 않는 메서드인 greeting을 접근하는 경우 applyDynamic 메서드 호출하며 name은 “greeting” args는 WrappedArray(“Daegeun Kim”)이다. args을 굳이 Any* 로 규정할 필요는 없습니다. Monday, January 7, 13
  • 11. applyDynamicNamed 존재하지 않는 멤버 메서드를 호출하는 경우 메서드명과 함께 입력한 파라메터를 applyDynamicNamed 메서드의 파라메터로 하여 호출한다. 단, applyDynamic과 다른 점 은 이름에서도 알 수 있듯이 Named Parameter 형태일 때 호출한다. Monday, January 7, 13
  • 12. class A extends Dynamic { def applyDynamicNamed(name: String)(args: (String, Any)*) { ... } } val a = new A a.greeting(name = “Daegeun Kim”, message = “Welcome”) 존재하지 않는 메서드인 greeting을 접근하는 경우 applyDynamicNamed 메서드 호출하 며 name은 “greeting” args는 WrappedArray((name,Daegeun Kim), (message,Welcome) 이다. Monday, January 7, 13
  • 13. 사용하려면? 2.10.0 에서도 간혹 경우에 따라 오류가 나는 경우가 있습니다. 되도록이면 RC버전이 아닌 2.10.x 버전에서 실행하세요. 2.9버전에서는 -Xexperimental 을 주고 실행하면 되지만 잘 안됩니다. Monday, January 7, 13
  • 14. scalac -language:dynamics scala -language:dynamics import language.dynamics SIP-18 - Modularizing Language Features 추가된 기능이고 dynamics feature를 활 성화 시키는 방법 설명입니다. SIP-18 또한 2.10 부터 정식 추가된 기능입니다. Monday, January 7, 13
  • 17. 물론, Dynamic 를 붙인 것 만 작업 Monday, January 7, 13
  • 18. 멤버(변수, 메서드) 없을 때만 해당! Monday, January 7, 13
  • 19. selectDynamic val a = new A a.name // a.selectDynamic(“name”) Monday, January 7, 13
  • 20. updateDynamic val a = new A a.name = “Daegeun Kim” // a.updateDynamic(“name”) (“Daegeun Kim”) Monday, January 7, 13
  • 21. applyDynamic val a = new A a.greeting(“Daegeun Kim”) // a.applyDynamic(“greeting”) (WrappedArray(“Daegeun Kim”)) 이전의 예를 기준으로 했을 때 위와 같이 재작성되고 항상 이렇게 되는건 아닙니다. Monday, January 7, 13
  • 22. applyDynamicNamed val a = new A a.greeting(name = “Daegeun Kim”) // a.applyDynamic(“greeting”) (WrappedArray((name,“Daegeun Kim”))) Monday, January 7, 13
  • 23. 필요한 곳에만 사용합시다. 필요한 곳에 시기적절하게 사용하는 것이 좋을 것 같고 제안한 목적처럼 유연한 DSL 구조를 가질 수 있는 곳에 사용하는 것이 좋다고 봅니다. Monday, January 7, 13
  • 24. 그럼 이만 마치도록 하겠습니다. 질문이 있으신가요? :-) 성의없지만 이렇게 마무리. 그리고 틀린 것이 있다면 조언 부탁드립니다. Monday, January 7, 13